DEV Community

Cover image for How to setup an ssh server within a docker container

How to setup an ssh server within a docker container

s1ntaxe770r on May 26, 2020

In this post I will walk you through my process of setting up ssh access to your docker container. Why run an ssh server within a contai...
Collapse
 
driftuazartur profile image
driftuazartur

Thanks, useful

Collapse
 
zim95 profile image
Namah Shrestha

For those of you who are trying to login with root creds. The user needs to be test and the password is test as well.
After creating the container hit: ssh test@ -p then hit test as the password.

Collapse
 
asidko profile image
Alexander Sidko

You may also want this line before RUN service ssh start

# Add test user to sudoers to skip sudo password asking
RUN echo 'test ALL=(ALL) NOPASSWD: ALL' | tee -a /etc/sudoers
Enter fullscreen mode Exit fullscreen mode
Collapse
 
davidkassa profile image
David Kassa

Thank you so much!

Collapse
 
tandavala profile image
Jose Tandavala

Thanks!

Collapse
 
jmielbrechtsymetrix profile image
Jordan Mielbrecht

Thank you so much!

One thing though: I attempted to run docker run IMAGE_NAME -p 22:22 but it gave me an error. Running docker run -p 22:22 IMAGE_NAME worked instead.

Collapse
 
amitrastogi2202 profile image
Amit Rastogi

Thanks a lot for this post. This helped me in setting up a docker container as a Jenkins build agent in my learning environment.

Collapse
 
bhavaniravi profile image
Bhavani Ravi

Is there a way to add public and private key authentication

Collapse
 
artemgrachov profile image
Artem Grachov

Thanks! :-)

Collapse
 
zakariae profile image
zakaria • Edited

Thanks for sharing.

Collapse
 
cheloneffa profile image
Marcelo Neffa

Thanks ! I was just looking for this configuration. It works fine

Collapse
 
m4n50n profile image
Jose Clemente García Rodríguez

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