7.docker centos7 安装sshd

  1. 拉取镜像
docker pull cenntos:7
  1. 运行容器并且附加端口映射
docker run -itd -p 22:22 --name centos7 centos:7 

3.进入到容器

docker attach 容器Id

4.安装系列工具

yum -y update
yum install passwd openssl openssh-server vim -y

5.启动sshd服务

/usr/sbin/sshd -D &

6.报错如下

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

7.解决错误并且重新运行

ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N '' 
ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''

8.修改配置文件

//UsePAM yes 改为 UsePAM no
//UsePrivilegeSeparation sandbox 改为 UsePrivilegeSeparation no
sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config
sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config
  1. 重新运行sshd服务
/usr/sbin/sshd -D &

10.修改密码

passwd root

11.使用putty或者xshell或者finalshell就可以连接登陆使用了。

你可能感兴趣的:(7.docker centos7 安装sshd)