OpenSSH升级版本(7.4升级到9)

发布时间 2023-04-23 16:39:21作者: WilliamShaw

 

 

ssh -V

### 1.为防止安装失败,无法用ssh做远程连接,因此先安装telnet防一手
yum -y install telnet*
systemctl enable telnet.socket
systemctl start telnet.socket
mv /etc/securetty /etc/securetty.bak
firewall-cmd --zone=public --add-port=23/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --zone=public --list-ports

### 2.安装依赖包
yum -y install zlib*
yum -y install pam-*
yum -y install gcc
yum -y install openssl-devel

### 3.备份原有yum安装的ssh服务版本
mv /etc/ssh /etc/ssh.bak
mv /usr/bin/ssh /usr/bin/ssh.bak
mv /usr/sbin/sshd /usr/sbin/sshd.bak

### 4.安装openssh
wget https://mirrors.aliyun.com/openssh/portable/openssh-9.3p1.tar.gz
tar -zxvf openssh-9.3p1.tar.gz
cd openssh-9.3p1
./configure --prefix=/usr/local/openssh --with-zlib=/usr/local/zlib --with-ssl-dir=/usr/local/ssl
make && make install

### 5.卸载由yum安装的openssh
yum remove openssh

### 6.修改配置
**启动前要将新生成的sshd_config修改以下几个地方**
vi /usr/local/openssh/etc/sshd_config
#PermitRootLogin prohibit-password
PermitRootLogin yes
#PubkeyAuthentication yes
PubkeyAuthentication yes
#PasswordAuthentication yes
PasswordAuthentication yes


**复制文件到相应系统文件夹**
cp /root/openssh-9.3p1/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


#启动
systemctl start sshd.service
#查看状态
systemctl status sshd.service

安装完成后使用xshell之类的工具登录,发现在输入密码后被拒绝,用下面方法解决
(1)考虑是否是selinux启用了策略,将/etc/selinux/config 文件中的SELINUX=enforcing 修改为 SELINUX=disabled
(2)setenforce 0

ssh -V