Centos5 源码升级sshd
1. 下载源码包
# openssh 下载地址
http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.4p1.tar.gz
# openssl 下载地址
https://www.openssl.org/source/old/0.9.x/openssl-0.9.8t.tar.gz
2. 编译安装openssl
# 需要修改Makefile 在 CFLAG 项中加入-fPIC
# 否则后续 OpenSSH 编译会报错 Can‘t find recent OpenSSL libcrypto
tar -zxvf openssl-0.9.8t.tar.gz
cd openssl-0.9.8t
./config
make
make install
mv /usr/bin/openssl /usr/bin/openssl.bak
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
3. 编译安装openssh
tar -zxvf openssh-7.4p1.tar.gz
cd openssh-7.4p1
./configure --with-ssl-dir=/usr/local/ssl
make
make install
4. 配置相关文件
mv /etc/ssh/ssh_config /etc/ssh/ssh_config.bak
cp openssh-7.4p1/ssh_config /etc/ssh/ssh_config
# 注意⚠️安装后的sshd配置文件路径: /usr/local/etc/sshd_config
# 允许root远程登陆
PermitRootLogin yes
# 允许root密码登陆
PasswordAuthentication yes
5. 设置开机启动
mv /etc/init.d/sshd /etc/init.d/sshd.bak
cp openssh-7.4p1/contrib/redhat/sshd.init /etc/init.d/sshd
# 默认低版本的ssh-keygen没有-A参数,启动会报错:ssh-keygen: illegal option -- A
# 更新 ssh-keygen
mv /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp /usr/local/bin/ssh-keygen /usr/bin/ssh-keygen
# 新版sshd安装路径在/usr/local/sbin/sshd
# 需要修改/etc/init.d/sshd:
# 修改 SSHD=/usr/sbin/sshd 为 SSHD=/usr/local/sbin/sshd
chmod u+x /etc/init.d/sshd
chkconfig --add sshd
chkconfig sshd on
6. 启动服务
service sshd restart
7. 查看版本
openssl version
ssh -V
telnet 127.0.0.1 22