1. yum升級到最新可用版本(openssh7.4p1)
yum update openssh
2. 安裝telnet-server 以及 xinetd
yum install xinetd telnet-server -y
3. 配置telnet登錄的終端類型,在/etc/securetty 文件末尾增加一些pts終端,如下
cat >> /etc/securetty <<EOF pts/0 pts/1 pts/2 pts/3 EOF
4.啟動telnet服務,並設置開機自動啟動
systemctl enable xinetd
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl start xinetd
5.使用telnet 登陸,以后操作都是通過telnet
6.備份並移除老文件 ( 這些配置可能影響裝完以后的登陸 所以備份)
mkdir /root/update cd /root/update cp /etc/ssh/sshd_config sshd_config cp /etc/pam.d/sshd sshd yum remove openssl-devel rm -rf /etc/ssl
7.安裝依賴包
yum install -y gcc gcc-c++ glibc make autoconf pcre-devel pam-devel yum install -y pam* zlib*
8.下載openssh包和openssl的包
# https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/ # https://ftp.openssl.org/source/ wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.5p1.tar.gz wget https://ftp.openssl.org/source/openssl-1.1.1k.tar.gz
9.安裝 openssl
tar xfz openssl-1.1.1k.tar.gz openssl version mv /usr/bin/openssl /usr/bin/openssl_bak cd openssl-1.1.1k ./config --prefix=/usr/local --openssldir=/usr/local/ssl make && make install ./config shared --prefix=/usr/local --openssldir=/usr/local/ssl make clean make && make install ln -s /usr/local/bin/openssl /usr/bin/openssl ln -s /usr/local/include/openssl /usr/include/openssl echo "/usr/local/lib" >> /etc/ld.so.conf echo "/usr/local/lib64" >> /etc/ld.so.conf /sbin/ldconfig openssl version
10.安裝openssh
rm -rf /etc/ssh cd /root/update tar xfz openssh-8.5p1.tar.gz cd openssh-8.5p1 ./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl --with-zlib --with-md5-passwords --with-pam make clean make && make install
cp -af contrib/redhat/sshd.init /etc/init.d/sshd cp -af contrib/redhat/sshd.pam /etc/pam.d/sshd.pam chmod +x /etc/init.d/sshd cat >> /etc/ssh/sshd_config <<EOF HostKey /etc/ssh/ssh_host_rsa_key HostKey /etc/ssh/ssh_host_ecdsa_key HostKey /etc/ssh/ssh_host_ed25519_key PermitRootLogin yes PasswordAuthentication yes ChallengeResponseAuthentication no UsePAM yes X11Forwarding yes
KexAlgorithms +diffie-hellman-group1-sha1 EOF chkconfig --add sshd mv /usr/lib/systemd/system/sshd.service /root/update/sshd.service chkconfig sshd on systemctl enable sshd systemctl restart sshd ssh -V
11.檢測ssh 可以正常登陸,使用ssh登陸,然后 停止telnet服務 並 移除
systemctl stop telnet.socket
systemctl stop xinetd
systemctl disable xinetd
systemctl disable telnet.socket
遇到的坑:
mv /usr/lib/systemd/system/sshd.service /root/update/sshd.service
這一步會導致sshd重啟后無法自啟動,解決辦法先卸載openssh
for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done
再重新安裝openssh 安裝后后需要還原/etc/pam.d/sshd 文件,原文件卸載時會被刪除
cat /etc/pam.d/sshd
#%PAM-1.0 auth required pam_sepermit.so auth substack password-auth auth include postlogin # Used with polkit to reauthorize users in remote sessions -auth optional pam_reauthorize.so prepare account required pam_nologin.so account include password-auth password include password-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open env_params session required pam_namespace.so session optional pam_keyinit.so force revoke session include password-auth session include postlogin # Used with polkit to reauthorize users in remote sessions -session optional pam_reauthorize.so prepare