First, start a pure CentOS container.
Docker run-it--name=sample Centos/bin/bash
Then the SSH localhost will find the following error.
Bash:ssh:command not found
Next I'll teach you how to ssh localhost.
Yum install openssh-server
yum install openssh-clients
Try ssh localhost again and find the error change:
Ssh:connect to host localhost port 22:cannot assign requested address
Indicates that the SSHD service is not yet open. This can also be verified with PS-EF.
Because it is docker inside CentOS, so service and systemctl are not good to use.
Try to run/usr/sbin/sshd manually
reported the following error:
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
sshd:no Hostkeys available--exiting.
Manual execution of/usr/sbin/sshd-keygen-a
Re-execution/usr/sbin/sshd successful.
To bypass this machine, perform the following command:
Ssh-keygen-t Rsa-p '-F ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys chmod 0600 ~/.ssh/
Authorized_keys
At this point, performing an ssh localhost can be successful.