限制 ssh 從某些 IP 登入( authorized_keys )
Restricting SSH logins to particular IP addresses
Posted by on Mon 28 Jan 2013 at 23:37
Many people use SSH keys for password-less logins, and the increase in security that keys provide over (traditionally weaker) passwords. But few people seem to realize that you can also restrict logins to known-good IP addresses, via that same mechanism.
It has to be said that if you've got root access upon a server one way to restrict people connecting to your machine is to use a firewall. The venerable iptables firewall primitive makes this easy.
However you can usefully use IP address restrictions even in combination with a firewall, for example you might wish to allow your users to login from within your network, but only allow an auto-build user to login from a remote jenkins server - to clone some source code, for example.
The basic mechanism is straight-forward enough, rather than just storing the public-part of a key to your users ~/.ssh/authorized_keys file you also store some configuration entries.
To restrict the user bob to remote logins from the single IP address 1.2.3.4 you would use this in the ~bob/.ssh/authorized_keys file:
from="1.2.3.4" ssh-rsa ....
Here we've added the "from="1.2.3.4"" section, prior to the key for the user. This is just one of the options you can add, and the quoted value is a list of comma-separated hosts from which the login will be allowed.
If you wished to allow logins from several sources you could use something like this:
from="1.2.3.0/24,44.55.66.77" ssh-rsa ...
In addition to the IP-address restrictions you can configure several other things, such as denying the use of agent-forwarding, denying the use of port-forwards, & etc.
The other options are comma-separated too, and are documented in the manpage for sshd, under the section "AUTHORIZED_KEYS FILE FORMAT". As a good example of a secure login this is a good start:
from="1.2.3.4",no-agent-forwarding,no-port-forwarding,no-X11-forwarding ssh-rsa ...
This disables the use of agent-forwarding, port-forwarding, etc. whilst still allowing interactive logins. If you were using SSH for special-purpose logins you could restrict things further, by denying interactive login-shells and forcing the execution of a particular command:
command="/usr/local/bin/my-prog" ssh-rsa ..
This is useful for remote backups carried out via rsync + ssh, as it can ensure that your remote user can only execute the expected command - and not anything else.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27042095/viewspace-2135229/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ORACLE限制IP登入Oracle
- shell禁止非法IP ssh登入
- 透過TRIGGER限制IP登入
- ssh禁止root登入及遮蔽指定ip
- oracle 登陸限制ipOracle
- iOS逆向之三 authorized_keys ssh登入越獄手機免驗證設定iOSZed
- 資料庫限制/允許某些IP訪問資料庫
- [zhuan]linux限制IP訪問sshLinux
- ssh設定使用者從指定的IP登陸
- 設定ssh只允許使用者從指定的ip登陸
- SSH遠端登入原理
- ssh免密登入原理
- SSH免密碼登入密碼
- Linux ssh登入命令Linux
- mysql localhost登入和tcp/ip登入MySqllocalhostTCP
- Oracle9i 中如何限制登陸IPOracle
- SSH免密登入詳解
- Linux 遠端 ssh 登入Linux
- Mac 上 ssh 別名登入Mac
- SSH 實現免密登入
- Linux配置SSH免登入Linux
- Linux修改SSH登入埠Linux
- linux使用SSH登入慢Linux
- 用SSH KEY遠端登入
- ssh遠端登入協議協議
- ssh進階,免密登入
- [20210518]ssh ip登入緩慢問題解決.txt
- 教訓:ssh或者securecrt登入到主機上時,不要看ssh或者securecrt標題中的ip地址Securecrt
- ssh免密登入簡單操作
- python中如何寫ssh登入Python
- Linux伺服器---ssh登入Linux伺服器
- Linux SSH無密碼登入Linux密碼
- Mac 下 SSH 免密碼登入Mac密碼
- ssh公鑰免密碼登入密碼
- SSH認證免密碼登入密碼
- ssh登入慢問題處理
- ansible 統計 ssh 登入資訊
- SSH 遠端登入「記住密碼」密碼