linux 讓ssh只允許指定的使用者登入的使用權限設定

來源:互聯網
上載者:User

方法一,只允許ssh指定使用者登入許可權的設定

SSH遠程登入的許可權直接影響伺服器的安全,為ssh設定合理的使用者權限是必須的。

查看ssh版本的命令:

ssh -v

設定ssh只允許指定使用者登入的方法

在/etc/ssh/sshd_config檔案中添加如下語句

允許admin可以在任何地方登入

AllowUsers admin

只允許指定ip地址的使用者可以登入

#允許root使用者只能在192.168.0.1地方登入

AllowUsers root@192.168.0.1

同時限制使用者名稱和ip登入ssh的方法

一行指定多使用者 ,用空格隔開。允許root使用者只能在192.168.0.1地方登入,允許admin可以在任何地方登入

AllowUsers root@192.168.0.1 admin

重啟SSH服務

service sshd restart

方法二總結

方法1:在/etc/pam.d/sshd檔案第一行加入

auth required pam_listfile.so item=user sense=allow file=/etc/sshusers
onerr=fail
然後在/etc下建立sshusers檔案,編輯這個檔案,加入你允許使用ssh服務的使用者名稱,不用重新啟動sshd服務。
添加2個使用者

zhangsan
lisisi        
 
方法2:pam規則也可以寫成deny的
auth required pam_listfile.so item=user sense=deny file=/etc/sshusers
onerr=succeed
方法3:pam規則可以使用group限制
auth required pam_listfile.so item=group sense=allow file=/etc/security/allow_groups onerr=fail
在allow_groups檔案按中加入組名,主要一定要加root

方法4:在sshd_config中設定AllowUsers,格式如
AllowUsers a b c
重啟sshd服務,則只有a/b/c3個使用者可以登陸

只允許某個IP以某個帳號登入伺服器?

只要在ssh的設定檔:sshd_config中添加如下一行即可

Allowusers username@192.168.1.100

上述只允許IP地址是192.168.1.100的機器以username使用者登入。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.