配置telnet,升級openssl和openssh防止升級失敗,ssh連接不上


1.安裝telnet-server以及xinetd

yum install xinetd telnet-server -y

2.如果下面文件存在,請更改配置telnet可以root登錄,把disable = no改成disable = yes

cat /etc/xinetd.d/telnet

default: on

description: The telnet server serves telnet sessions; it uses \

unencrypted username/password pairs for authentication.

service telnet
{
disable = yes
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}

3.啟動telnet服務,並設置開機自動啟動

systemctl enable xinetd

systemctl enable telnet.socket

systemctl start telnet.socket

systemctl start xinetd

netstat -lntp|grep 23

useradd telnet 創建用戶

****echo 123456 | passwd --stdin telnet

4.切換到telnet方式登錄,以后的操作都在telnet終端下操作,防止ssh連接意外中斷造成升級失敗

學會應用快捷鍵(alt+Q)會彈出一個對話框。
SecureCRT創建telnet連接

##########################################################################################
openssl升級, 升級需要幾個組件,有些是和編譯相關的等
###########################################################

yum install -y gcc gcc-c++ glibc make autoconf openssl

               openssl-devel pcre-devel  pam-devel

2.安裝pam和zlib等(后面的升級操作可能沒用到pam,安裝上也沒啥影響,
如果不想安裝pam請自行測試)

yum install -y pam* zlib*

3.下載openssh包和openssl的包
openssh: https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/
openssl: https://ftp.openssl.org/source/

4.開始安裝openssl

mkdir data

cd data/

wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz

wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz

[root@node01 ~]# openssl version #當前版本
OpenSSL 1.0.2k-fips 26 Jan 2017

mv /usr/bin/openssl /usr/bin/openssl.bak

mv /usr/include/openssl/ /usr/include/openssl.bak

tar xvf openssl-1.1.1h.tar.gz

cd openssl-1.1.1h/

./config shared && make && make install

echo $?

which openssl

/usr/local/bin/openssl

ln -s /usr/local/bin/openssl /usr/bin/openssl

ln -s /usr/local/include/openssl /usr/include/openssl

ll /usr/bin/openssl

lrwxrwxrwx 1 root root 22 11月 21 17:42 /usr/bin/openssl -> /usr/local/bin/openssl

ll /usr/include/openssl -ld

添加命令加載新配置

vim /etc/ld.so.conf

include ld.so.conf.d/*.conf
/usr/local/openssl/lib

/usr/sbin/ldconfig 加載

4.查看版本號
[root@node01 ~]# openssl version
OpenSSL 1.1.1h 22 Sep 2020 已經升級成功
##################################################################
openssh升級
###################################################
[root@node01 ~]# ssh -V 查看版本號
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017


1.移除舊版本

mv /etc/ssh /etc/ssh.old

需要注意,移除之后,不能退出當前終端,若退出,只能通過telnet連了

2.下載解壓編譯安裝

wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz

tar -zxvf openssh-8.0p1.tar.gz

cd openssh-8.0p1/

chown -R root.root /root/openssh-8.0p1

./configure --prefix=/usr/local/openssh --sysconfdir=/etc/ssh --with-pam --with-ssl-dir=/usr/local/openssl --with-md5-passwords --mandir=/usr/share/man --with-zlib=/usr/local/zlib --without-hardening

make && make install

4.修改啟動腳本

拷貝啟動腳本

[root@node01 openssh-8.0p1]#cp ./contrib/redhat/sshd.init /etc/init.d/sshd

修改啟動腳本

vim /etc/init.d/sshd

按如下圖修改,需要注意,此路徑是你安裝新版本的openssh路徑,根據你的實際情況修改

SSHD=/usr/local/openssh/sbin/sshd

注意根據自身情況修改路徑

/usr/local/openssh/bin/ssh-keygen –A
/sbin/restorecon /etc/ssh/ssh_host_key.pub
/sbin/restorecon /etc/ssh/ssh_host_rsa_key.pub
/sbin/restorecon /etc/ssh/ssh_host_dsa_key.pub
/sbin/restorecon /etc/ssh/ssh_host_ecdsa_key.pub

5、修改sshd配置文件/etc/ssh/sshd_config

echo "PermitRootLogin yes" >> /etc/ssh/sshd_config

直接用root登錄終端(此處根據自身情況考慮)

echo 'X11Forwarding yes' >> /etc/ssh/sshd_config

設置是否允許X11轉發

echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config

是否允許密碼驗證

6.卸載原有ssh(先安裝后卸載,也是怕升級失敗,如果有把握,可先卸載)
for i in $(rpm -qa |grep openssh);do rpm -e $i --nodeps ;done

將警告中被修改的文件名字再改回來
mv /etc/ssh/sshd_config.rpmsave /etc/ssh/sshd_config

mv /etc/ssh/ssh_config.rpmsave /etc/ssh/ssh_config

mv /etc/ssh/moduli.rpmsave /etc/ssh/moduli

7.替換相關命令,並重啟sshd服務

cp -arp /usr/local/openssh/bin/* /usr/bin/ 替換相關命令

systemctl restart sshd 重啟sshd服務

8.查看版本
[root@node01 ~]# ssh -V
OpenSSH_8.0p1, OpenSSL 1.1.1h 22 Sep 2020

9、設置開機自啟
chkconfig --add sshd

chkconfig --level 2345 sshd on

chkconfig --list

10.升級測試完成后,為了安全起見,建議關閉telnet

關閉服務(此處根據自身情況考慮)

systemctl stop telnet.socket
systemctl stop xinetd

關閉服務開機自啟(此處根據自身情況考慮)

systemctl disable xinetd.service
systemctl disable telnet.socket


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM