启动容器
docker pull centos:7
docker run -d -name centos --privileged=true -p 222:22 centos:7 /usr/sbin/init
docker exec -it centos /bin/bash
安装环境
进入容器后安装sshd
# 安装sshd,开启sshd
yum install openssh-server -y
systemctl start sshd
# 配置sshd,配置如下几项
vi /etc/ssh/sshd_config
-----
Port 22
#AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
-----
PermitRootLogin yes
-----
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
# 重启sshd
systemctl restart sshd
安装passwd
yum install passwd
# 设置root密码
passwd root
连接测试
选择222端口,输入配置的密码连接成功
评论区