ssh命令使用


ssh是什么

ssh是一種通信協議,用於與另一台計算機通信,有多個實現版本,openssh屬於開源實現

usage: ssh [-B bind_interface]
           [-b bind_address] 
           [-c cipher_spec] 
           [-D [bind_address:]port]
           [-E log_file] 
           [-e escape_char] 
           [-F configfile] 
           [-I pkcs11]
           [-i identity_file] 
           [-J [user@]host[:port]] 
           [-L address]
           [-l login_name] 
           [-m mac_spec] 
           [-O ctl_cmd] 
           [-o option] 
           [-p port]
           [-Q query_option] 
           [-R address] 
           [-S ctl_path] 
           [-W host:port]
           [-w local_tun[:remote_tun]] destination [command]

//root賬戶登錄
ssh xxx.xxx.xxx 

//指定用戶 -l
ssh -l root xxx.xxx.xxx
ssh root@xxx.xxx.xxx

//指定端口 -p
ssh -p 123 xxx.xxx.xxx or
ssh -l root -p 123 xxx.xxx.xxx or
ssh -p 123 root@xxx.xxx.xxx

中間人攻擊

假設有中間人冒充用戶主機的情況

口令登錄

$ ssh user@host
  The authenticity of host 'host (xxx.xxx.xxx.xxx)' can't be established.
  RSA key fingerprint is 98:2e:d7:e0:de:9f:ac:67:28:c2:42:2d:37:16:58:4d.
  Are you sure you want to continue connecting (yes/no)?
  
//基於中間人攻擊問題,所以第一次登錄無法確認主機安全性,可以根據RSA加密提供的key與遠程主機的公鑰進行對比

登錄成功后

$ cat ~/.ssh/known_hosts

//用戶系統會自動把當前公鑰存起來
//下次連接這台主機時就知道這台主機的身份了,跳過警告部分

登錄失敗的情況

//因為密碼輸錯了,所以登錄不了
root@xxx.xxx.xx password: 
Permission denied, please try again.

公/私鑰對

公鑰和私鑰是成對的,它們互相解密。

公鑰加密,私鑰解密。

私鑰數字簽名,公鑰驗證。

公鑰登錄

$ ssh-keygen
//一路回車在~/.ssh/下生成2把鑰匙

$ ssh-copy-id user@host
//將公鑰傳到主機

//公鑰被放在 ~/.ssh/authorized_keys 

失敗解決

// ubuntu系統 ssh進程重啟命令
service ssh restart
// debian系統 ssh進程重啟命令
/etc/init.d/ssh restart


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM