Skip to content

Instantly share code, notes, and snippets.

@gasi
Created June 1, 2013 20:04
Show Gist options
  • Save gasi/5691565 to your computer and use it in GitHub Desktop.
Save gasi/5691565 to your computer and use it in GitHub Desktop.
Setting up an SSH server on @dotcloud docker CentOS image
# Install OpenSSH server and SSH client
yum install -y openssh-server
yum install -y openssh-clients
# Install passwd
yum install -y passwd
# Set root password
passwd
# TODO: Enter new root password
# TODO: Repeat new root password
# Test ssh
ssh root@localhost
# Enter root password when prompted
# ERROR: Connection to localhost closed.
# ERROR: Exit status 254
@gasi
Copy link
Author

gasi commented Jun 1, 2013

Based on tutorial for @dotcloud docker base image (Ubuntu):
http://docs.docker.io/en/latest/examples/running_ssh_service.html

@pungoyal
Copy link

to fix, add to your docker file:

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config

@matachi
Copy link

matachi commented Jan 4, 2014

I also got "Exit status 254" when connecting to a Docker container of stackbrew/ubuntu:13.10 running openssh-server.

Changing UsePAM yes to UsePAM no inside /etc/ssh/sshd_config solved it. Dunno what that setting does though.

@pcting
Copy link

pcting commented Mar 6, 2014

I encountered the same problem.

Check out this: http://docs.docker.io/en/latest/examples/running_ssh_service/

At the bottom, it states the following:

    For Ubuntu 13.10 using stackbrew/ubuntu, you may need do these additional steps:

    change /etc/pam.d/sshd, pam_loginuid line ‘required’ to ‘optional’
    echo LANG=”en_US.UTF-8” > /etc/default/locale

@cressie176
Copy link

Changing UsePAM yes to UsePAM no inside /etc/ssh/sshd_config solved it.

Solved it for us too. Thanks.

You can check if it's a PAM issue by starting a container and overriding the CMD to run sshd in the foreground...

$ docker run -i -t -p 127.0.0.1::22 our-base-ubuntu:13.10 /usr/sbin/sshd -D -e
Server listening on 0.0.0.0 port 22.
Server listening on :: port 22.
Accepted password for fred from 192.168.42.1 port 40892 ssh2
PAM: pam_open_session(): Cannot make/remove an entry for the specified session
Received disconnect from 192.168.42.1: 11: disconnected by user

@jnav
Copy link

jnav commented May 15, 2014

@pungoyal Thank you! It helped me too!

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config

@conradkleinespel
Copy link

Thanks for the tip on UsePAM. Works great! Been looking for a solution for like an hour. 👍

Still, I wonder why it does that.

@larrycai
Copy link

larrycai commented Jul 3, 2014

I guess this PAM setting is not needed since docker 1.0.0

@JulesWang
Copy link

PAM setting is not needed +1

@ernetas
Copy link

ernetas commented Feb 7, 2015

PAM setting is still needed (Docker 1.4, phusion/baseimage:latest). -1

@stoleas
Copy link

stoleas commented Oct 18, 2015

For automating the passwd part

( sleep .1 ; printf "%s\n" "password" "password" ) | passwd

Then password could be easily editable through other means using Jinja during deployment or something...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment