Mac的公钥地址,以及通过终端连接远程服务器Connection refused的处理方案

Mac系统的公钥文件存储地址:

localhost:~ mingqi$ cd ~/.ssh/
localhost:.ssh mingqi$ ls
id_rsa		id_rsa.pub	known_hosts

今天在尝试连接远程服务器的时候发现被拒绝了,很无奈。

localhost:~ mingqi$ ssh root@目标ip
ssh: connect to host xx.xx.xx.xxx port 22: Connection refused
localhost:~ mingqi$ ssh [email protected]
ssh: connect to host xx.xx.xx.xxx port 22: Connection refused

没办法,以前还得输密码,直接搞一下本地的免密登录远程吧

找到本地秘钥,远程发送到服务器

中间需要手动输一次远程服务器的登录密码,跑完即可通过ssh命令连接尝试

localhost:.ssh mingqi$ ssh-copy-id -i ./id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "./id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

localhost:.ssh mingqi$ ssh [email protected]
Welcome to Ubuntu 16.04.4 LTS (GNU/Linux 4.4.0-117-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
New release '18.04.2 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Welcome to Alibaba Cloud Elastic Compute Service !

Last login: Fri Oct 11 09:53:58 2019 from 12.34.56.789
root@hello:~# 

直接免密登陆,搞定~

备注:所有的IP地址均为伪造,注意使用自己的IP!

你可能感兴趣的:(Linux)