1. In order to prevent installation failure, you cannot use ssh for remote connection, so install telnet first to prevent it.
yum -y install telnet*
systemctl enable telnet.socket
systemctl start telnet.socket
Note: The security file must be closed or modified (otherwise root cannot log in via telnet)
mv /etc/securetty /etc/securetty.bak
Note: If you have a firewall, you need to open port 23
firewall-cmd --zone=public --add-port=23/tcp --permanent
Restart the firewall: systemctl restart firewalld.service
View all open ports on the firewall: firewall-cmd --zone=public --list-ports
2. Install dependency packages
yum -y install zlib*
yum -y install pam-*
yum -y install gcc
yum -y install openssl-devel
3. Back up the original ssh service version
mv /etc/ssh /etc/ssh.bak
mv /usr/bin/ssh /usr/bin/ssh.bak
mv /usr/sbin/sshd /usr/sbin/sshd.bak
4. Install openssh
download address:
http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/
What I downloaded is: openssh-9.0p1.tar.gz
tar -zxvf openssh-9.0p1.tar.gz
cd openssh-9.0p1
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install
5. Uninstall openssh installed by yum: yum remove openssh
6. Modify the configuration.
Before starting, modify the newly generated sshd_config in the following places:
vim /usr/local/openssh/etc/sshd_config
Copy the file to the corresponding system folder
cp /root/openssh-9.0p1/contrib/redhat/sshd.init /etc/init.d/sshd
chkconfig --add sshd
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp/usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
7. Start
#Start systemctl start sshd.service
# to check the status systemctl status sshd.service
. Add auto-start at boot: systemctl enable sshd.service
8. Last verified version:ssh -V