当前位置:首页 > centos open-ssh升级到8.3p1

centos open-ssh升级到8.3p1

点击次数:2317  更新日期:2020-08-24

1. 安装必要组件:

yum install -y gcc openssl-devel pam-devel rpm-build

2. 下载OpenSSH最新版本:

wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.3p1.tar.gz

tar -xvf openssh-8.3p1.tar.gz

3. 到openssh-8.3p1目录下编译并安装最新版OpenSSH:

cd openssh-8.3p1

./configure --prefix=/usr --sysconfdir=/etc/ssh --with-zlib --with-md5-passwords --with-tcp-wrappers


4. 如果没报错则执行安装命令

make && make install

5. 查看OpenSSH版本信息

ssh -V


6. 检查配置 将下面几个开启

vi /etc/ssh/sshd_config

PermitRootLogin yes 

PubkeyAuthentication yes 

PasswordAuthentication yes


7. 设置权限

chmod 600 /etc/ssh/ssh_host_rsa_key

chmod 600 /etc/ssh/ssh_host_ecdsa_key

chmod 600 /etc/ssh/ssh_host_ed25519_key


8. 关闭 Selinux

setenforce 0 #临时关闭Selinux

如果要永久关闭,修改/etc/selinux/config 文件,

将SELINUX=enforcing改为SELINUX=disabled


9. 重启

service sshd restart


如果出现以下异常

/etc/ssh/sshd_config line 81: Unsupported option GSSAPIAuthentication

/etc/ssh/sshd_config line 83: Unsupported option GSSAPICleanupCredentials

则注释掉相关行数即可。


# 验证操作

 ssh -V


# ssh反复重启?

查看日志发现ssh在不停的重启

Aug 23 23:11:11 localhost systemd: sshd.service failed.
Aug 23 23:11:53 localhost systemd: sshd.service holdoff time over, scheduling restart.
Aug 23 23:11:53 localhost systemd: Stopped OpenSSH server daemon.
Aug 23 23:11:53 localhost systemd: Starting OpenSSH server daemon...
Aug 23 23:13:23 localhost systemd: sshd.service start operation timed out. Terminating.
Aug 23 23:13:24 localhost systemd: Failed to start OpenSSH server daemon.
Aug 23 23:13:24 localhost systemd: Unit sshd.service entered failed state.
Aug 23 23:13:24 localhost systemd: sshd.service failed.
Aug 23 23:14:06 localhost systemd: sshd.service holdoff time over, scheduling restart.
Aug 23 23:14:06 localhost systemd: Stopped OpenSSH server daemon.
Aug 23 23:14:06 localhost systemd: Starting OpenSSH server daemon...
Aug 23 23:15:36 localhost systemd: sshd.service start operation timed out. Terminating.
Aug 23 23:15:36 localhost systemd: Failed to start OpenSSH server daemon.
Aug 23 23:15:36 localhost systemd: Unit sshd.service entered failed state.

解释: 出现命令挂起的原因就是 sshd在启动完成后,没有给systemd发消息,systemd就一直在那傻等,所以下面我们就修改源码,添加消息;


源码修改:

  在源码openssh-8.3p1目录下,找sshd.c这个主函数文件,找到调用server_accept_loop 这个函数的行,注意这个函数的定义也在这个文件,不要找错了!

前加一行代码,效果如下:

/* Signal systemd that we are ready to accept connections */
sd_notify(0, "READY=1");
/* Accept a connection and return in a forked child */
server_accept_loop(&sock_in, &sock_out,&newsock, config_s);


相应的,在源文件开头几行添加引用头文件:

#include <systemd/sd-daemon.h>


编译,安装

由于默认的依赖中,不包含sd_notify 这个函数,所以还需要安装依赖的包

yum install systemd-devel

编译时还需要在makefile中指明,编辑文件:Makefile ,找到变量 LIBS,修改如下:

LIBS=-lcrypto -ldl -lutil -lz -lcrypt -lresolv -lsystemd

下面就可以直接编译,安装

make & make install