SSH限制某些使用者 ip登入

2021-09-03 10:54:15 字數 588 閱讀 1739

1,只允許某個ip登入,拒絕其他所有ip

在 /etc/hosts.allow 寫:

sshd: 1.2.3.4

在 /etc/hosts.deny 寫:

sshd: all

用 iptables 也行:

iptables -i input -p tcp --dport 22 -j drop

iptables -i input -p tcp --dport 22 -s 1.2.3.4 -j accept

2,禁止某個使用者通過ssh登入

在/etc/ssh/sshd_conf新增

allowusers 使用者名稱

或者allowgroups 組名

或者denyusers 使用者名稱

3,設定登入黑名單

vi /etc/pam.d/sshd

增加auth required /lib/security/pam_listfile.so item=user sense=deny file=/etc/sshd_user_deny_list onerr=succeed

所有/etc/sshd_user_deny_list裡面的使用者被拒絕ssh登入

在CentOS 上SSH限制IP及使用者登入

centos 下設定ssh只允許特定使用者從特定的ip登入,其它未經允許的使用者和ip都不能登入。演示環境192.168.1.81 centos 6 192.168.0.222 win 10 192.168.1.135 win 8.1 未做任何設定時192.168.0.222和192.168.1.1...

centOS 7配置ssh 限制ip登入

環境 centos 7.0 ps 因本人外網ip非固定ip除了方法一在putty中配置沒問題外沒有在其餘外網ip親測 公司也不搞個固定ip,我還能說啥 方法一 首先需要限制登入的ip 外網ip 為外網ip vim etc hosts.allow 輸入sshd allowvim etc hosts.d...

ssh限制ip連線

1.兩種解決方案 第二種不生效,沒有解決,後續有時間再試吧 第一種簡單暴力,只允許指定使用者,ip訪問 目錄 etc ssh sshd config 配置相應ip訪問 permitrootlogin yes 允許root使用者登陸放開 allowusers root ip address 重啟ssh...