apt-get update apt-get install openssh-server openssh-client
修改/etc/ssh/sshd_config文件,找到PermitRootLogin,参数修改成yeslinux
vim /etc/ssh/sshd_config
使用passwd root命令修改root登陆密码docker
passwd root
以下是不存在密匙vim
root@c223a9d1c7a0:/home# ll /etc/ssh total 560 drwxr-xr-x 1 root root 4096 Oct 10 03:29 ./ drwxr-xr-x 1 root root 4096 Oct 10 03:32 ../ -rw-r--r-- 1 root root 553122 Feb 10 2018 moduli -rw-r--r-- 1 root root 1580 Feb 10 2018 ssh_config -rw-r--r-- 1 root root 3800 Oct 10 03:29 sshd_config
生成主机密匙(执行以下命令时能够一路回车):ssh
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
exit命令退出容器学习
docker commit <容器id> <镜像名称>
把容器的22端口映射到虚拟机的8122端口加密
docker run --name <容器名称> -i -t -p 8122:22 <镜像ID> /usr/sbin/sshd -D
ssh root@localhost -p 8122code
终身学习!