1、SSH登陆/登出命令
$ ssh <hostname> #登入 $ exit #登出
- known_hosts
- 每个用户都有自己的known_hosts文件,路径:(username)/.ssh/known_hosts
- /etc/目录下的known_hosts文件
2、登录方式:
- 输入密码登陆
- 公钥登陆
1 $ ssh-keygen # 可以加入相关参数选择加密方式,如[-t rsa] 2 #将生成的密钥对中的公钥拷贝到远程服务器上 3 $ scp /Users/(local_username)/.ssh/id_rsa.pub [email protected]_host: 4 5 #另一种方式:ssh-copy-id 6 # 附:mac下ssh-copy-id command not found解决办法: 7 # $brew install ssh-copy-id 8 9 #这里的例子里*.pub文件名为id_rsa.pub, 远程主机用户名vagrant, IP:192.168.33.10 10 $ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]192.168.33.10 11 /usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed 12 /usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys 13 [email protected]192.168.33.10‘s password: #此处需要输入密码 14 15 Number of key(s) added: 1 16 17 Now try logging into the machine, with: "ssh ‘[email protected]‘" 18 and check to make sure that only the key(s) you wanted were added. 19 $
参考资料:
http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html