openssh升級到8.4版本

openssh升級到8.0版本後發現最大連接數在普通用戶下不能更改,查閱資料發現是升級8.0的時候操作步驟有問題,經研究之後整理一下,並分享給大家。此次升級直接升級openssh8.4版本。
1.查看openssh現在的版本:

#sshd -V
unknown option -- V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
usage: sshd [-46DdeiqTt] [-C connection_spec] [-c host_cert_file]
            [-E log_file] [-f config_file] [-g login_grace_time]
            [-h host_key_file] [-o option] [-p port] [-u len]

2.查看openssh安裝的方式:

#rpm -qa|grep openssh
openssh-clients-7.4p1-16.el7.x86_64
openssh-7.4p1-16.el7.x86_64
openssh-server-7.4p1-16.el7.x86_64

建議:如果是物理機爲了避免openssh升級出現故障,在升級前建議安裝telnet,使用yum安裝步驟如下:

 yum install -y telnet-server xinetd --安裝  

echo -e 'pts/0\pts/1\npts/2\pts/3'  >>/etc/securetty  

 systemctl enable xinetd.service  

 systemctl enable telnet.socket  

 systemctl start telnet.socket  

 systemctl start xinetd  

如果是虛擬機可以使用回滾的方式,使用yum安裝原來版本的openssh
3.備份文件,需要備份的是openssh從來都沒有升級過的文件,對於openfile非常重要:

mkdir /openssh.bak
cp /etc/pam.d/sshd /openssh.bak

4.卸載原openssh的安裝包:
rpm安裝,卸載方式:

 rpm -e `rpm -qa | grep openssh` --nodeps  

源碼安裝的,找到之前的安裝包,在裏面執行 :

make uninstall  

5安裝升級必要的軟件:

yum -y install gcc pam pam-devel zlib zlib-devel openssl-devel

6.開始升級openssh8.4版本:
解壓壓縮文件:

tar -xf openssh-8.4p1.tar.gz

進入到openssh目錄下:

cd openssh-8.4p1/

進行如下操作:

 ./configure  --prefix=/usr  --sysconfdir=/etc/ssh  --with-pam
 make&make install

常出現了報錯:

ssh-keygen: generating new host keys: DSA 
/usr/sbin/sshd -t -f /etc/ssh/sshd_config
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
sshd: no hostkeys available -- exiting.
make: [check-config] Error 1 (ignored)
[1]+  Exit 2                  make

解決辦法:

chmod 600 /etc/ssh/ssh_host_*

繼續升級:

cp contrib/redhat/sshd.pam /etc/pam.d/sshd
install -v -m755 contrib/ssh-copy-id /usr/bin
install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1
install -v -m755 -d /usr/share/doc/openssh-8.4p1
install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-8.4p1
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
echo 'UsePAM yes' >> /etc/ssh/sshd_config
cp -p contrib/redhat/sshd.init /etc/init.d/sshd 
cp /openssh.bak/sshd /etc/pam.d/sshd
chmod +x /etc/init.d/sshd 
chkconfig --add sshd
chkconfig sshd on 
chkconfig --list sshd

查看升級後的版本:

sshd -V
unknown option -- V
OpenSSH_8.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
usage: sshd [-46DdeiqTt] [-C connection_spec] [-c host_cert_file]
            [-E log_file] [-f config_file] [-g login_grace_time]
            [-h host_key_file] [-o option] [-p port] [-u len]

重啓ssh服務:

systemctl restart sshd 

7.修改open file參數:
在vim /etc/security/limits.conf配置文件裏最後一行添加:

 * soft nofile 65535
 * hard nofile 65535
 :wq!

8.切換到普通用戶下驗證最大連接數,顯示升級成功:

ulimit -n
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章