docker add sshd service

1、docker run -it centos /bin/bash

2、yum install openssh-server

3. / usr / sbin / sshd -D will prompt to report an error first / usr / sbin / sshd-keygen -A

  passwd root 给root创建密码

[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

0b70e5bbf7f5 centos "/bin/bash" 9 minutes ago Exited (127) 6 seconds ago

4. docker commit 0b7 sshd: centos saves the image you just changed

5、[root@localhost ~]# docker run -p 10022:22 -d sshd:centos /usr/sbin/sshd -D 运行镜像
3b7a664d4705bb5880fc29b2aed4850a111046024ec4310ebff3b40bfabade0c
6、[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

3b7a664d4705 sshd:centos "/usr/sbin/sshd -D" 43 seconds ago Up 41 seconds

7. Choose to log in on the client

ssh [email protected] 10022 Enter the root password

You can choose to use the key to log in. Enter ssh-keygen -t rsa three times and save the contents of cat /root/.ssh/id_rsa.pub to the container /root/.ssh/authorized_keys
—————————— ——————
Copyright Statement: This article is an original article of CSDN blogger “maibm”, following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement for reprint.
Original link: https://blog.csdn.net/maibm/article/details/80226478

Guess you like

Origin www.cnblogs.com/jiftle/p/12691804.html