centos7 openssh升级至8.6

安装telnet

yum install xinetd 
yum install telnet-server

配置 telnet 登录的终端类型

vim /etc/securetty

添加 :

pts/0
pts/1
pts/2
pts/3

启动 telnet 服务,并设置开机自动启动

systemctl start telnet.socket
systemctl enable telnet.socket

开放23端口:

vim /etc/firewalld/direct.xml

添加:

-p tcp --dport 23 -j ACCEPT

重启firewalld生效:

systemctl restart firewalld

查看端口监听状态、确认 telnet 工作状态

netstat -lntp|grep 23

添加防火墙规则

firewall-cmd --add-service=telnet --permanent
firewall-cmd --reload
firewall-cmd --list-all

测试telnet

# telnet 192.168.100.100
# 输入用户名密码 
 回车登录

openssh升级

下载openssh升级包及依赖的zlib和openssl
https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/openssh-8.3.tar.gz
http://www.zlib.net/zlib-1.2.11.tar.gz
https://www.openssl.org/source/openssl-1.1.1g.tar.gz
openssh-8.6p1.tar.gz openssl-1.1.1g.tar.gz zlib-1.2.11.tar.gz

解压缩各个包:

tar -xzvf ...
openssh-8.6p1.tar.gz 
openssl-1.1.1g.tar.gz 
zlib-1.2.11.tar.gz

编译安装zlib

1.  cd zlib-1.2.11
2.  ./configure --prefix=/usr/local/zlib
3.  make && make install

编译安装openssl

1.  cd openssl-1.1.1g
2.  ./config --prefix=/usr/local/ssl -d shared
3.  make && make install
4.  echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
5.  ldconfig -v

安装openssh

1.  cd openssh-8.3p1
2.  ./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
3.  make && make install

sshd_config文件修改

echo 'PermitRootLogin yes' >>/usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >>/usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes' >>/usr/local/openssh/etc/sshd_config

备份原有文件,并将新的配置复制到指定目录

mv /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config

mv /usr/sbin/sshd /usr/sbin/sshd.bak
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd

mv /usr/bin/ssh /usr/bin/ssh.bak
cp /usr/local/openssh/bin/ssh /usr/bin/ssh

mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen

mv /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub

配置启动文件

  1. 从原先的解压的包中拷贝一些文件到目标位置(如果目标目录存在就覆盖)
cp -a contrib/redhat/sshd.init /etc/init.d/sshd
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam 
chmod +x /etc/init.d/sshd 
chkconfig --add sshd 
systemctl enable sshd
  1. 把原先的 systemd 管理的 sshd 文件删除或者移走或者删除,不移走的话影响我们重启 sshd 服务
mv  /usr/lib/systemd/system/sshd.service ./dir_name_path

配置开机启动

chkconfig sshd on

测试sshd服务

/etc/init.d/sshd restart
netstat -lntp | grep 22
/etc/init.d/sshd stop注意:相关的重启测试,要确保已安装telnet,且可使用telnet正常登陆
/etc/init.d/sshd start
systemctl status sshd
ssh -V
sync
reboot now 注意:相关的重启测试,要确保已安装telnet,且可使用telnet正常登陆

升级后节点ssh失败问题:

删除对应的公钥即可,即.ssh/known_hosts文件中对应的公钥(所有相关节点的信息都要删除)
ps:删除前做好备份

你可能感兴趣的:(centos7 openssh升级至8.6)