docker in centos7 install ssh service

Source: https: //blog.csdn.net/qq_32969313/article/details/64919735

 

After docker installed, yourself to be a docker own image, you first need a basic image from the server pull, here with centos7
(preferably under the root user, my virtual machine docker docker prompt ordinary users to run the service is not running , strange)
First, download the official original image

CentOS pull Docker: 7
1
wait a little longer the download is complete, use

ImagesRF Royalty Free Docker
1
Check local mirror list, as shown, centos that was just downloaded


Then use the following command to start, use the image to create a container and into the interactive mode, login shell is / bin / bash

RUN -i -t centos Docker:. 7 / bin / the bash
. 1
then the terminal is the centos the container, the default is the root user login, the next operation in the container
two, the vessel mounting passwd, openssl, openssh- server

the install the passwd OpenSSL OpenSSH-yum Server -Y
. 1
after installation
start sshd:

# /usr/sbin/sshd -D
1
这时报以下错误:
[root@ b3426410ff43 /]# /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

Execute the following command to solve:

[@ b3426410ff43 the root /] # SSH-RSA keygen -b 2048 -t -q -f / etc / SSH / ssh_host_rsa_key -N ''
[@ b3426410ff43 the root /] # SSH-keygen -t ECDSA -q -f / etc / SSH / ssh_host_ecdsa_key -N ''
[@ b3426410ff43 the root /] # DSA SSH-keygen -t -f / etc / SSH / ssh_host_ed25519_key -N ''
. 1
2
. 3
then, modify / etc / ssh / sshd_config configuration information:
UsePAM change Yes UsePAM no is
changed UsePrivilegeSeparation no UsePrivilegeSeparation sandbox
can be changed vi, the following command can be used

[@ b3426410ff43 the root /] -i # Sed "S / UsePrivilegeSeparation #. * / UsePrivilegeSeparation NO / G" / etc / SSH / the sshd_config
[@ b3426410ff43 the root /] -i # Sed "S / UsePAM. * / UsePAM NO / G "/ etc / SSH / sshd_config
1
2
after modification, restart sshd

[root @ b3426410ff43 /] # / usr / sbin / the sshd -D
. 1
and modified root password

the root the passwd
. 1
or a modified directly

echo "123456" | passwd root --stdin
1
then need to save the modified image, first enter exit to exit the container, and then use the following command to see just run off,
Docker modified after the commit will save the image to a local parameter is the ID ,first name

PS -all #docker
CONTAINER ID PORTS the STATUS the IMAGE CREATED the COMMAND NAMES
b3426410ff43 CentOS:. 7 "/ bin / the bash". 4 minutes ago Member the Exited (0) ago Member centos7ssh. 4 seconds The
#docker the commit b5926410fe60 myImage / centos7ssh
. 1
2
. 3
. 4
next time just enter the name of saving the modified start the installation of the mirror ssh service.
---------------------
Disclaimer: This article is CSDN blogger "Yao __ 'original article, follow the CC 4.0 by-sa copyright agreements, please attach a reprint the original source link and this statement.
Original link: https: //blog.csdn.net/qq_32969313/article/details/64919735

Guess you like

Origin www.cnblogs.com/0to9/p/11309587.html