服务器信息:
# cat /etc/redhat-release
CentOS release 6.10 (Final)
一、安装并启用telnet服务端
安装telnet服务端用于在ssh升级过程中备用登录方案。
yum -y install telnet-server* telnet
yum -y install gcc-c++,zlib,zlib-devel,openssl,openssl-devel,pam-devel
#修改配置文件将disable的yes改为no
vi /etc/xinetd.d/telnet
# /etc/xinetd.d/telnet
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no
}
# 启动telnet服务
service xinetd start
# 开机启动
chkconfig xinetd on
# telnet默认禁止root账号登录。可以先建一个普通账号.
useradd xxxx
passwd xxxx
通过telnet客户端登录服务器
telnet 192.168.1.20
# Trying 192.168.1.20...
# Connected to 192.168.1.20.
# Escape character is '^]'.
# Password:
Login incorrect
# host001 login: xxxx
# Password:
# 正确输入账号密码即可登录服务器
# 登录后可以通过su切换root账号
su root
二、下载openssh并安装
cd /usr/local/src/
wget http://ftp.jaist.ac.jp/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
tar zvxf openssh-8.2p1.tar.gz
cd openssh-8.2p1
# 进行编译安装
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-zlib --with-md5-passwords --with-pam --with-tcp-wrappers && make && make install
# 替换相关默认配置
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin\ yes/g' /etc/ssh/sshd_config
sed -i 's/#PermitEmptyPasswords\(.*\)/PermitEmptyPasswords\ no/g' /etc/ssh/sshd_config
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
sed -i 's/GSSAPICleanupCredentials yes/#GSSAPICleanupCredentials yes/' /etc/ssh/sshd_config
sed -i 's/GSSAPIAuthentication yes/#GSSAPIAuthentication yes/' /etc/ssh/sshd_config
# 备份原服务
cp /etc/init.d/sshd /etc/init.d/sshd.bak
# 覆盖原服务
cp contrib/redhat/sshd.init /etc/init.d/sshd
# 设置开机自启动
chkconfig --add sshd
chkconfig sshd on
# 重启ssh服务
service sshd resstart
# 查看版本
ssh -V
# 在客户端ssh登录服务器,检查是否正常登录
三、以上步骤都没有问题可以关闭telnet远程登录
# 经disable no改为yes
vi /etc/xinetd.d/telnet
# 停止telnet服务
service xinetd stop
至此升级完成。