有过硬的需求,必须要在一个docker实例中启动sshd服务,centos7的image。

执行yum -y install openssh-server openssh-clients,启动的话,直接使用systemctl start sshd,在docker里是会报错的,如下:

Failed to get D-Bus connection: No connection to service manager.

直接命令启动(修改端口为10001):

# `which sshd` -D &>> sshd.log &
[1] 89

# cat sshd.log 
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key

出现上述错误,用客户端登录,xshell或ssh命令,分别报错如下:

Read from socket failed: Connection reset by peer

Google后查到解决方案:

/usr/bin/ssh-keygen -A

执行后生成相应key,再启动就可以了!

Google资料:https://bbs.archlinux.org/viewtopic.php?id=165382

·End·