一、环境
centos7.9,升级openssh到8.8p1最新版本
二、下载升级包
# openssl和zlib为相关依赖
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.8p1.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1j.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
三、编译安装
1、确认安装了gcc编译环境
# yum install -y gcc gcc-c++(yum安装gcc编译环境)
2、编译安装zlib
# tar -zxvf zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure --prefix=/usr/local/zlib
# make && make install
新建并编辑配置文件
vim /etc/ld.so.conf.d/zlib.conf
添加如下内容后保存退出
/usr/local/zlib/lib
.刷新
ldconfig -v
3、编译安装openssl
# tar -zxvf openssl-1.1.1j.tar.gz
# cd openssl-1.1.1j
# ./config --prefix=/usr/local/ssl -d shared
# make && make install
# echo '/usr/local/ssl/lib' >> /etc/ld.so.conf
# ldconfig -v
# /usr/local/ssl/bin/openssl version -a
4、编译安装openssh
# tar -zxvf openssh-8.8p1.tar.gz
# cd openssh-8.8p1
# ./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
# 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
# 修改systemd参数(去掉Type或改为Type=simple)
vim /usr/lib/systemd/system/sshd.service
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service
[Service]
#Type=notify
Type=simple
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
五、重启sshd服务
[root@server1 openssh-8.8p1]# systemctl daemon-reload
[root@server1 openssh-8.8p1]# systemctl restart sshd
[root@server1 openssh-8.8p1]# systemctl status sshd
六、注意
如果要修改ssh的配置文件必须得修改/usr/local/openssh/etc/sshd_config,修改/etc/ssh/sshd_config不会生效。