docker启动sshd报错Could not load host key: /etc/ssh/ssh_host_rsa_key和Permissions 0640 for ‘/etc/ssh/ssh_

启动sshd报错

第一个错误,docker容器启动sshd没有文件

[root@3ca6bba2a824 yum.repos.d]# /usr/sbin/sshd               
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
sshd: no hostkeys available -- exiting.

只需要从宿主机把这个三个文件cp到容器内就可以解决

[root@zheng ssh]# docker cp /etc/ssh/ssh_host_rsa_key 3ca6bba2a824:/etc/ssh/
[root@zheng ssh]# docker cp /etc/ssh/ssh_host_ecdsa_key 3ca6bba2a824:/etc/ssh/
[root@zheng ssh]# docker cp /etc/ssh/ssh_host_ed25519_key 3ca6bba2a824:/etc/ssh/

再从容器启动sshd还是报错

第二个错误,文件权限错误,复制过来的权限太高了

[root@3ca6bba2a824 ansible]# /usr/sbin/sshd
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_rsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_rsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ecdsa_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0640 for '/etc/ssh/ssh_host_ed25519_key' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
key_load_private: bad permissions
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.

修改一下这三个文件的权限,改成600
然后查询一下进程和端口确认

[root@3ca6bba2a824 ssh]# chmod 600 ssh_host_ecdsa_key
[root@3ca6bba2a824 ssh]# chmod 600 ssh_host_ed25519_key
[root@3ca6bba2a824 ssh]# chmod 600 ssh_host_rsa_key
[root@3ca6bba2a824 ssh]# /usr/sbin/sshd

[root@3ca6bba2a824 ssh]# ps -ef |grep sshd
root        212      0  0 07:49 ?        00:00:00 /usr/sbin/sshd
root        214    193  0 07:50 pts/3    00:00:00 grep --color=auto sshd

看到了22端口
[root@3ca6bba2a824 ssh]#  netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      212/sshd            
tcp6       0      0 :::22                   :::*                    LISTEN      212/sshd   

解决成功

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值