歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux 如何禁止root使用ssh登錄及修改ssh端口

Linux 如何禁止root使用ssh登錄及修改ssh端口

日期:2017/3/2 10:08:41   编辑:關於Linux

1、禁止root用戶登錄ssh

#vi /etc/ssh/sshd_config

PermitRootLogin yes
改為
PermitRootLogin no
重啟sshd服務
#service sshd restart

此時再使用root登錄就會被提示拒絕:

login as: root
[email protected]'s password:
Access denied

2、修改ssh默認端口

vi /etc/ssh/sshd_config
找到#Port 22一段,這裡是標識默認使用22端口,修改為如下:
Port 22
Port 7000
然後保存退出
重啟sshd服務
#service sshd restart

注意:此時使用22端口和7000應該都可以登錄,這樣就避免了在調試時失誤(如調整端口後沒有調整相應的防火牆策略)導致不能使用ssh登錄服務器的情況。
使用ssh客戶端並用7000端口登錄測試,無誤後再將/etc/ssh/sshd_config配置文件下的Port 22一句注釋並重啟sshd服務即可。

Linux 如何禁止root使用ssh登錄及修改ssh端口
Linux 如何禁止root使用ssh登錄及修改ssh端口
Copyright © Linux教程網 All Rights Reserved