An SSH image which only allows key login.
The user can only login with it's ssh key file. The password login is disabled by default.
Use the outside VOLUME to control the image start command, don't need to rebuild the image any more.
(Optional) Build image from git
If you want to buid the image yourself:
You need to install docker first. If you don't know how to do this, refer to : docker.com
Clone this repo:
git clone https://github.com/karas1999/docker-ssh-key.git path_to_docker-ssh
Build the image:
docker build -t myssh path_to_docker-ssh
Get image from docker hub (Suggested)
Open your docker terminal
Pull the image from docker:
docker pull karasshi/ssh-key
How to run container
You need to generate you own ssh key pairs. If you don't know what they are and what to do, refer to : SSH Keys
When you got your own "id_rsa.pub" file, copy that file to a folder which will be passed to the container as a volume. It must be in a folder called "sshkey" and must be named "authorized_keys". For example:
cp ~/.ssh/id_rsa.pub ~/volume/sshkey/authorized_keys
Make a start.sh file in "volume" folder to control the start process of the container:
Make a new file called start.sh.
Edit the file as follow:
#!/bin/bash echo 'Begin start.sh...' # You can add any command you need here: # Copy the user-defined public keys to ssh /bin/cp /vol/sshkey/authorized_keys /home/admin/.ssh/authorized_keys # Start ssh server /usr/sbin/sshd -D echo 'start.sh ended.'
Save the file in
Run the container with commands below:
docker run -d -P --name testssh -v ~/volume:/vol karasshi/ssh-key
Find the port:
docker port testssh 22 > 0.0.0.0:32779
How to login
Find you docker host's IP, for example: 192.168.1.100
Login to the container:
ssh firstname.lastname@example.org -p 32779
NOTE1: You can only use the username "admin".
NOTE2: You can not use the password to login, you can only use the machine which contains you own private key in ~/.ssh
I followed all instructions, then I got error: Permission denied (publickey). if I try to ssh