2、增強服務器安全等級——修改服務器默認登錄端口

我們默認通過ssh登錄的端口是22,這個端口是默認的也就意味著這個端口對于所有人是透明的,如果你買臺服務器,沒有經(jīng)過修改的話,那別人就等于已經(jīng)猜到你的登錄端口是22。出于基本的安全考慮,我們是需要修改一下這個端口的。

1、修改配置文件: /etc/ssh/sshd_config

配置文件中的內容:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
LogLevel INFO

# Authentication:
LoginGraceTime 120
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile     %h/.ssh/authorized_keys

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

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# 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
# PAM authentication via ChallengeResponseAuthentication may bypass
# If you just want the PAM account and session checks to run without
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
UseDNS no
AddressFamily inet
PermitRootLogin yes
SyslogFacility AUTHPRIV
PasswordAuthentication yes

2、在改之前需要先新建一個連接窗口,保持登錄狀態(tài),防止修改失敗導致ssh連不上。

3、端口的范圍是0-65536

由于0-1024最好不要使用,因為這些可能是被系統(tǒng)默認占用的端口,所以我們配置端口時為了避免和系統(tǒng)端口沖突,最好采用1024以后的端口。

端口號改成39999
UseDNS保證為no
底部加一行允許登錄的用戶
重啟ssh

測試:

嘗試用22連接被拒絕
使用39999端口登錄成功

如果登錄依然不成功的話,可能是阿里云的安全組配置規(guī)則需要修改:

具體可參考文檔:
https://yq.aliyun.com/articles/168203

4、修改配置文件,不允許root用戶登錄:

修改配置文件中PermitRootLogin為no

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 134,981評論 19 139
  • 端口:0 服務:Reserved 說明:通常用于分析操作系統(tǒng)。這一方法能夠工作是因為在一些系統(tǒng)中“0”是無效端口,...
    蕭玄辭閱讀 1,226評論 0 2
  • ssh 遠程登錄服務器 命令行輸入 然后輸入密碼,進入遠程阿里云服務器。這里的 ip 地址是我的阿里云服務器的公網(wǎng)...
    輝夜乀閱讀 1,275評論 0 0
  • 和顧先生好久沒見,這兩天稍微打了幾個電話,內容大多就是互相拆臺吐槽。 前幾天去做了護照,打算找時間和顧...
    封景家的傻蘑菇閱讀 328評論 0 0
  • 那一次,好友的感情出現(xiàn)了危機。她哭著打電話向我吐苦水,而我總能像一片汪洋海,囊括她的所有辛酸苦辣。我...
    矢崎美智子閱讀 246評論 0 2