centos升级ssh
服务器漏洞扫描,提示很多ssh漏洞,原因是因为centos6.5的ssh版本太低,需要升级。
升级步骤:
1、备份ssh目录
mv /etc/ssh /etc/ssh-bak或
cp -rf /etc/ssh /etc/ssh-bak
2、下载ssh最新版,我下载的是openssh-7.6p1.tar.gz
http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/
3、执行安装命令
tar -zxvf openssh-7.6p1.tar.gz
cd openssh-7.6p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords --with-tcp-wrappers
(在执行以上这条命令时,如出现error的错误,代表这里缺少依赖包,可根据不同提示信息进行下载安装,缺少包的情况会有:zlib、openssl-devel、pam等)
注:此处我遇到错误提示configure: error: PAM headers not found,执行yum install pam-devel -y
make && make install
4、修改配置文件/etc/ssh/sshd_config
PermitRootLogin 项 改为yes
PasswordAuthentication 值改为yes
5、重启ssh
service sshd restart
注:此处我遇到错误提示:Generating SSH1 RSA host key: FAILED,百度上未搜到解决办法,后来想起之前备份的/etc/ssh,恢复到以前的,问题解决。
6、查看ssh版本
ssh -V
===========================centos6.5升级openssh到最新的9.0版本=======================
按照之前的方法操作后,一直报错
原因:OpenSSH从8.8版本由于安全原因开始弃用了rsa加密的密钥
解决办法:在sshd_config最后增加两行代码
HostKeyAlgorithms=+ssh-rsa,ssh-dss
KexAlgorithms=+diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
参考资料:https://blog.csdn.net/charlie2cindy/article/details/121523155
其它报错如:
注释掉对应的配置项即可
可能会用到的
如果有报错,可以用systemctl status sshd查看状态,sshd -t查看报错详情
journalctl -xe
20201201 ygb遇到问题:sshd重启命令卡住,没有反应
参考资料:
https://www.cnblogs.com/dukeShi/p/8134061.html
http://blog.c1gstudio.com/archives/1474
https://blog.csdn.net/lqy461929569/article/details/76148598
https://blog.csdn.net/u012259256/article/details/59546084
CentOS7参考资料
https://www.cnblogs.com/chillax1314/p/13858655.html
https://blog.csdn.net/jackyzhousales/article/details/84144770
rpm -qa |grep openssh
for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps;done
tar -xvf openssh-7.9p1.tar.gz
cd openssh-7.9p1
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords--with-pam --with-tcp-wrappers --with-ssl-dir=/usr/local/ssl --without-hardening
rm -rf /etc/ssh
make && make install
cp contrib/redhat/sshd.init /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
chkconfig --list|grep sshd
sed -i "32a PermitRootLogin yes" /etc/ssh/sshd_config
systemctl restart sshd
systemctl status sshd