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 root@xx.xx.xx.xxx
ssh: connect to host xx.xx.xx.xxx port 22: Connection refused

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

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

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

localhost:.ssh mingqi$ ssh-copy-id -i ./id_rsa.pub root@12.34.56.789
/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
root@12.34.56.789's password: 

Number of key(s) added:        1

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

localhost:.ssh mingqi$ ssh root@12.34.56.789
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!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值