Last active
August 29, 2015 13:57
-
-
Save Mulkave/9746487 to your computer and use it in GitHub Desktop.
A Dockerfile for Fedora/CentOS/Red Hat based systems that runs with enabled ssh access using ssh keys.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# | |
# setup: | |
# - generate an ssh key to be used as an authentication key with `ssh-keygen` and call it `docker_ssh_rsa` | |
# - make sure your current ssh agent has the identity file added | |
# - $ eval `ssh-agent` | |
# - $ ssh-add docker_ssh_rsa | |
# | |
# build: $ sudo docker build -t <you>/ssh . | |
# | |
# run: $ sudo docker run -d -p 8022:22 <you>/ssh | |
# | |
# ssh: $ ssh root@localhost -p 8022 | |
# | |
## | |
FROM centos:latest | |
MAINTAINER Abed Halawi <[email protected]> | |
# install openssh server | |
RUN yum -y install openssh-server | |
# install openssh clients | |
RUN yum -y install openssh-clients | |
# make ssh directories | |
RUN mkdir /root/.ssh | |
RUN mkdir /var/run/sshd | |
# create host keys | |
RUN ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_key | |
RUN ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_rsa_key | |
RUN ssh-keygen -b 1024 -t dsa -f /etc/ssh/ssh_host_dsa_key | |
# move public key to enable ssh keys login | |
ADD docker_ssh.pub /root/.ssh/authorized_keys | |
RUN chmod 400 /root/.ssh/authorized_keys | |
RUN chown root:root /root/.ssh/authorized_keys | |
# tell ssh to not use ugly PAM | |
RUN sed -i 's/UsePAM\syes/UsePAM no/' /etc/ssh/sshd_config | |
# make the terminal prettier | |
RUN echo 'export PS1="[\u@docker] \W # "' >> /root/.bash_profile | |
# enable networking | |
RUN echo 'NETWORKING=yes' >> /etc/sysconfig/network | |
EXPOSE 80 | |
EXPOSE 22 | |
ENTRYPOINT ["/usr/sbin/sshd"] | |
CMD ["-D"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment