1. 程式人生 > 其它 >CentOS ssh版本升級

CentOS ssh版本升級

1、升級openssl

yum install perl
wget https://goodrain-delivery.oss-cn-hangzhou.aliyuncs.com/fuzhoushuchan/openssl-1.1.1g.tar.gz && tar xvf openssl-1.1.1g.tar.gz && cd openssl-1.1.1g/
./config --prefix=/usr/local/ssl   #如果此步驟報錯,需要安裝perl以及gcc包
make && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
ln -sf /usr/local/ssl/bin/openssl /usr/bin/openssl
echo "/usr/local/ssl/lib" >> /etc/ld.so.conf
ldconfig -v 
$ openssl version
OpenSSL 1.1.1g  21 Apr 2020

2、升級openssh

1)下載最新opnssh軟體
專案地址:https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/

wget https://goodrain-delivery.oss-cn-hangzhou.aliyuncs.com/fuzhoushuchan/openssh-8.8p1.tar.gz && tar xvf openssh-8.8p1.tar.gz && cd openssh-8.8p1/

2)安裝依賴包

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

3)備份

mkdir /etc/ssh_bak
mv /etc/ssh/* /etc/ssh_bak

3)解壓、編譯、安裝

./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib --with-pam --with-md5-password --with-ssl-engine --with-selinux  --host x86_64
make && make install

8.6:
./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-openssl-includes=/usr/local/ssl/include --with-ssl-dir=/usr/local/ssl   --with-zlib   --with-md5-passwords   --with-pam  && make && make install

4)修改配置檔案(按照實際情況配置,見文末)

vi /etc/ssh/sshd_config
# 這三行改為 yes
PermitRootLogin yes #這項一定要改成yes,否則登陸不進去
PubkeyAuthentication yes
PasswordAuthentication yes

5)移走以前的ssh服務, 防止與新的衝突

mv /usr/lib/systemd/system/sshd.service /etc/ssh_bak/sshd.service
mv /usr/lib/systemd/system/sshd.socket /etc/ssh_bak/sshd.socket

6)在解壓包中拷貝一些檔案

cp -a contrib/redhat/sshd.init /etc/init.d/sshd

7)重新啟動ssh

/etc/init.d/sshd restart
systemctl daemon-reload

8)新增自啟動

chkconfig --add sshd
chkconfig sshd on

檢視:

$ chkconfig --list sshd

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

sshd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

1表示:單使用者模式
2表示:無網路連線的多使用者命令列模式
3表示:有網路連線的多使用者命令列模式
4表示:不可用
5表示:帶圖形介面的多使用者模式
6表示:重新啟動

9)檢測升級版本

$ ssh -V
OpenSSH_8.8p1, OpenSSL 1.1.1g  21 Apr 2020

sshd_config檔案

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key


# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to no to disable s/key passwords
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no


# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem	sftp	/usr/libexec/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	X11Forwarding no
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS