Operating System: VM centos6.5
Container: docker
Prerequisites: you can create an SSH-enabled docker image.
Method 1: manually create
1. generate a new key and public key on the host machine
### Ssh-keygen [-q] [-B bits]-T type [-N new_passphrase] [-C comment] [-foutput_keyfile] # ssh-keygen usage reference official ssh-keygen-Q-n ""-t dsa-F/root /. SSH/id_dsa
2. then place the public key in the created docker container.
ssh -o StrictHostKeyChecking=no [email protected]mkdir -p /root/.sshecho "..." >> /root/.ssh/authorized_keys
3. Test the SSH connection on the host machine
[[email protected]_admin_192.168.240.148_61618_A ~]$ ssh 172.17.0.2 Last login: Sat Aug 2 11:16:10 2014 from 172.17.42.1 [[email protected]_admin_172.17.0.2_22_A ~]$
Method 2: Create a script
The principle is the same. Both generate the key and public key, and then import the key.
This article is from the "O & M Pawn" blog and will not be reposted!