1、备份原有文件
mkdir ssh.bak
cp /etc/ssh/* /etc/ssh.bak
2、安装并启动Telnet
yum install telnet telnet-server xinetd -y
systemctl start telnet.socket
systemctl start xinetd
//设置开机自启动
systemctl enable telnet.socket
systemctl enable xinetd
//添加Telnet配置文件
vi /etc/xinetd.d/telnet
//添加下列语句
# default: on
# description: The telnet server serves telnet sessions; it uses \
# unencrypted username/password pairs for authentication.
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no //默认为yes时,不允许root登录
}
vi /etc/securetty
//添加下列语句,允许远程设备使用root账号登录
pts/0
pts/1
3、卸载旧版本ssh(Telnet登录)
systemctl stop sshd
//查询已安装的openssh包
rpm -qa | grep openssh
//结果
openssh-server-7.4p1-16.el7.x86_64
openssh-clients-7.4p1-16.el7.x86_64
openssh-7.4p1-16.el7.x86_64
//卸载
rpm -e openssh* --nodeps
//删除配置文件
rm -rf /etc/ssh/*
4、安装ssh
上传ssh安装包并解压到/usr/local/openssh
目录
tar -zxvf /usr/local/openssh/openssh-8.3p1.tar.gz
安装依赖包
yum install -y gcc openssl-devel pam-devel rpm-build
编译安装,在/usr/local/openssh/openssh-8.3p1
目录下执行
./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords
make
make install
5、修改配置
修改配置文件
vi /etc/ssh/sshd_config
//取消下列行注释,若无则添加
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes
复制启动文件到/etc/rc.d/init.d/sshd
cp /usr/local/openssh/openssh-8.3p1/contrib/redhat/sshd.init /etc/rc.d/init.d/sshd
启动sshd服务
service sshd start //先用service命令启动后才可使用systemctl命令
ssh -V //查看ssh版本
chkconfig sshd on //设置开机启动