Menu
blog.headdesk.me
blog.headdesk.me

Deploy a sshd docker container

Posted on 2017/10/052017/10/05

Here are some quick steps to deploy a sshd docker container. It will be based on the official CentOS 7 image from docker hub. It can be used as a light-weight ssh jump server.

First, pull the CentOS 7 image

# docker pull centos:7

Next, create a temp directory. Create a Dockerfile inside with the following content.

FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
RUN yum -y install openssh-server openssh-clients
RUN echo root:pass | chpasswd
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
RUN ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]

Build the docker image

# docker build -t docker-sshd .

And it’s ready to be ran. Start it up and forward port 22000 to port 22 inside the container

# docker run -p 22000:22 docker-sshd

You can now ssh to the container. Password is set in the Dockerfile.

# ssh -p22000 [email protected]
[[email protected] ~]# ssh -V
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017

 

facebookShare on Facebook
TwitterTweet

1 thought on “Deploy a sshd docker container”

  1. Danny says:
    2018/09/26 at 02:41

    Thanks for posting this.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Full text search

Recent Posts

  • Terraform and segregated permissions
  • LVM Compression and Deduplication
  • Edit gpg encrypted file with vim
  • Lelit Elizabeth PL92T Pressure Tuning
  • jq transformation
  • aws (8)
  • coffee (1)
  • headfi (1)
  • linux (6)
  • others (58)
  • security (2)
  • tech (36)
  • wordpress (2)

apache aws awscli azure backup clearlinux cloud coffee docker DOCP ec2 EL8 epyc espresso featured gpg jenkins kernel lelit linux lvm meltdown memory MFA mikrotik php python rdp Redhat RHEL roasting rpm Ryzen site-to-site snapshot spectre tech terraform tuning ubuntu ubuntu upgrade vim vpn wordpress xdotool

©2023 blog.headdesk.me | Powered by SuperbThemes & WordPress