- 很多人都搞不懂如何在Linux上面實作SSH,
這邊我就簡易說明一下。
以一個使用者(user)的身分產生密鑰在/home/user/.ssh/底下
[shell]cd /home/user/.ssh
[shell]ssh-keygen -t rsa
將公鑰灌進去
[shell]cd authorized_keys
[shell]cat id_rsa.pub >> authorized_keys [tell]灌公鑰進去[/tell]
[shell]chmod 400 authorized_keys [tell]設定authorized_keys權限[/tell]
設定sshd_config
[shell]vim /etc/ssh/sshd_config
[vim]Protocol 2
ServerKeyBits 1024
PermitRootLogin no [com]禁止root登錄[/com]
[com]以下三行沒什麼要改的,把默認的#註釋去掉就行了[/com]
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no [com]KEY與密碼一定要選一個[/com]
PermitEmptyPasswords no [com]禁止使用空密碼登入[/com]
設定哪些IP可使用SSH連線
/etc/hosts.allow 允許此IP使用SSH登入
/etc/hosts.deny 拒絕此IP使用SSH登入
[shell]vim /etc/hosts.allow
[vim][com]允許此ip使用SSH登入[/com]
sshd:192.168.10.130[/vim]
[shell]vim /etc/host.deny
[vim][com]限制IP使用SSH 連線[/com]
sshd:all[/vim]
重啟服務
[shell]service sshd restart
client連線(私鑰)
[shell]ssh -i id_rsa [email protected]
[tell]用root登入遠端,選擇私鑰 id_rsa[/tell]