美文网首页
mac os解决Could not load host key:

mac os解决Could not load host key:

作者: bitcarmanlee | 来源:发表于2017-10-01 22:48 被阅读0次

1.问题描述

想通过scp把mac上的本地jar包传输到服务器上去,结果发现报了如下错误:

ssh: connect to host xx.xx.xx.xx port 22: Connection refused

然后在服务器上试着ping了一下mac的ip,发现能ping通,很明显,那这是sshd服务的问题。

2.mac上的sshd服务

回头再mac上再查一把,果然发现没有sshd的服务,只有ssh-agent

ps -ef | grep ssh
  501  2301     1   0  9:36下午 ??         0:00.06 /usr/bin/ssh-agent -l

应该是macOs上默认不会自动开启sshd服务,所以需要手动开启一下。
查了一下资料,可以用如下方式启动sshd服务

sudo /usr/sbin/sshd

结果又华丽丽的报了一堆错:

sudo /usr/sbin/sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key

哎,这很明显是/etc/ssh里没有对应的密钥对

3.生成对应的密钥对

解决起来就比较简单了,生成对应的密钥对即可。

sudo ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key
sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ed25519_key

此时/etc/ssh里就多了4对密钥对

屏幕快照 2017-10-01 下午10.44.46.png

这个时候再启动sshd服务

sudo /usr/sbin/sshd

不再报错,顺利启动!

grep sshd
    0  2622     1   0 10:10下午 ??         0:00.00 /usr/sbin/sshd

相关文章

网友评论

      本文标题:mac os解决Could not load host key:

      本文链接:https://www.haomeiwen.com/subject/tezaextx.html