歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> linux 控制sshd的遠程訪問

linux 控制sshd的遠程訪問

日期:2017/3/1 12:20:56   编辑:關於Linux
測試環境:linux centos6.5 1、hosts.allow文件配置: 修改/etc/hosts.allow文件 # # hosts.allow This file describes the names of the hosts which are # allowed to use the local INET services, as decided # by the ‘/usr/sbin/tcpd’ server. # sshd:210.13.218.*:allow sshd:222.77.15.*:allow 以上寫法表示允許210和222兩個ip段連接sshd服務(這必然需要和hosts.deny這個文件配合使用),當然“:allow” 完全可以省略的。當然如果管理員集中在一個IP那麼這樣寫是比較省事的 all:218.24.129.110//他表示接受110這個ip的所有請求! 2、hosts.deny文件配置 /etc/hosts.deny文件,此文件是拒絕服務列表,文件內容如下: # # hosts.deny This file describes the names of the hosts which are # *not* allowed to use the local INET services, as decided # by the ‘/usr/sbin/tcpd’ server. # # The portmap line is redundant, but it is left to remind you that # the new secure portmap uses hosts.deny and hosts.allow. In particular # you should know that NFS uses portmap! sshd:all:deny 注意看:sshd:all:deny表示拒絕了所有sshd遠程連接。:deny可以省略。 所以:當hosts.allow和 host.deny相沖突時,以hosts.allow設置為准。 修改完成後立刻生效。 3、擴展: 1.禁止所有ip訪問linux 的ssh功能 可以在/etc/hosts.deny添加一行 sshd:all:deny 2.禁止某一個ip(192.168.11.112)訪問ssh功能 可以在/etc/hosts.deny添加一行sshd:192.168.11.112 3.如果在/etc/hosts.deny和/etc/hosts.allow同時 有sshd:192.168.11.112 規則,則192.168.11.112可以訪問主機的ssh服務 總結:通過這種方法可以控制部分非授權訪問,但不是一勞永逸的方法!我們在看服務日志的時候或許會看到很多掃描記錄,不是還是直接針對root用戶的,這時控制你的訪問列表就非常有作用了!
Copyright © Linux教程網 All Rights Reserved