Docker centos7 install SSH specific steps _docker

Source: Internet
Author: User
Tags openssl ssh centos docker ps docker hub docker run

Docker Centos7 installs SSH concrete steps, here record, also can help to read the article friend.

A. Download CentOS official image from Docker hub

Hr:centos7 hr$ Docker Pull Centos:7 

When you are finished downloading, view the local repository: Hr:centos7 hr$ docker images the REPOSITORY      TAG         IMAGE ID      CREATED       VIRTUAL SIZE
  centos        7          ce20c473cd8a    7 weeks ago     172.3 MB


Run container
Hr:centos7 hr$ Docker run-i-T centos:7/bin/bash

Two. Install Passwd,openssl,openssh-server

 [root@b5926410fe60/]# yum install passwd OpenSSL openssh-server-y start sshd: #/usr/sbin  /sshd-d this times the following error: [root@ b5926410fe60/]#/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 executes the following command to resolve: [root@b5926410f  E60/]# ssh-keygen-q-t rsa-b 2048-f/etc/ssh/ssh_host_rsa_key-n ' [root@b5926410fe60/]# ssh-keygen-q-T Ecdsa-f  /etc/ssh/ssh_host_ecdsa_key-n ' [root@b5926410fe60/]# ssh-keygen-t dsa-f/etc/ssh/ssh_host_ed25519_key-n '] then, modify /etc/ssh/sshd_config configuration information: usepam Yes to Usepam no useprivilegeseparation sandbox to Useprivilegeseparation no [root@b5 926410fe60/]# sed-i "s/#UsePrivilegeSeparation. */useprivilegeseparation no/g"/etc/ssh/sshd_config [ Root@b5926410fe60/]# sed-i "S/usepam.*/usepam no/g"/etc/ssh/sshd_config after the modification, restart sshd [Root@b5926410fe60/]#/usr/sbi n/sshd-d 

Three. Modify Root password

[Root@b5926410fe60/]# passwd Root

Four. View the container IP address (skip this step if the host is a Linux operating system)

[root@b5926410fe60/]# IP addr ls eth0
84:eth0@if85: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc noqueue s Tate up 
  link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff inet 172.17.0.2/16
  scope global eth0
    valid_lft Forever Preferred_lft Forever
  inet6 fe80::42:acff:fe11:2/64 scope link Valid_lft forever Preferred_lft forever 
    

Five. Save the current container as a mirror

Hr:centos7 hr$ Docker ps-all
CONTAINER ID IMAGE    COMMAND    CREATED       STATUS          PORTS   NAMES
b5926410fe60 centos:7  "/bin/bash" 4 minutes ago    exited (0) 4 seconds ago      centos7ssh

hr: Centos7 hr$ Docker commit B5926410fe60 Herong/centos7-ssh

Six. Start a new container on the host based on a newly created mirror

--First delete the previous container
hr:centos7 hr$ Docker ps-all
CONTAINER ID    IMAGE   COMMAND       CREATED       STATUS           PORTS        NAMES
4122f818a741    herong/centos7-ssh:latest  "/usr/sbin/sshd"  seconds ago   Exited (0) seconds ago            Happy_mclean hr:centos7 hr$ Docker rm-f 4122f818a741


--running container HR based on a new mirror
: Centos7 hr$ Docker run-d-P 10022:22 herong/centos7-ssh:latest/usr/sbin/sshd-d

--View mapped port success
Hr:centos7 hr$ D Ocker ps-all
CONTAINER ID    IMAGE   COMMAND        CREATED       STATUS       PORTS          NAMES
4966D35FE0A3    herong/centos7-ssh:latest  "/usr/sbin/sshd-d"  3 seconds ago up    3 seconds    0.0.0.0:10022->22/tcp  Compassionate_kowalevski

hr:centos7 hr$ Docker Port 4966d35fe0a3
22/tcp- > 0.0.0.0:10022

Seven. Connecting from host to container

  W If the host is a non-Linux operating system, you need to connect to the container via Docker-machine IP-
  view docker-machine IP address
  hr:centos7 hr$ docker-machine IP Default
  192.168.99.100

  --connect to the container via Docker-machine IP, enter the password previously set to login successfully
  Hr:centos7 hr$ SSH Root@192.168.99.100-p 10022 The
  authenticity of host ' [192.168.99.100]:10022 ([192.168.99.100]:10022) ' Can ' t be Established.
  ECDSA key fingerprint is SHA256:D3JNCKCTVV1ASJLWV+IT/BJWLZMC4U1T/PMSKYIHMHQ.
  Are you sure your want to continue connecting (yes/no)? Yes
  warning:permanently added ' [192.168.99.100]:10022 ' (ECDSA) to the list of known hosts.
  Root@192.168.99.100 ' s password: 
  [root@4966d35fe0a3 ~]# pwd
  /root


  W If the host is a Linux operating system, the IP address is connected through the 4th step
  hr:centos7 hr$ ssh root@172.17.0.2-p 10022

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.