Skip to content

Instantly share code, notes, and snippets.

@benlast
Created August 5, 2016 16:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save benlast/b95d568ff61cc4c0b88de35e7aafe931 to your computer and use it in GitHub Desktop.
Save benlast/b95d568ff61cc4c0b88de35e7aafe931 to your computer and use it in GitHub Desktop.
SSH image support for PyCharm
#!/usr/bin/env bash
# Put a docker build command here to build your main image
# Generate or re-use SSH keys. The ssh_keys directory should
# be in .gitignore
mkdir -p ssh_keys
if [ ! -f ssh_keys/docker-sshd ] ; then
echo "Generating SSH key"
# Remove any associated public key also
rm -f ssh_keys/docker-sshd*
ssh-keygen -t rsa -f ssh_keys/docker-sshd -N ""
else
echo "Using existing SSH key"
fi
# Now build the sshd server image, which should be based on
# the main image.
docker build --force-rm=true -f docker/Dockerfile \
--build-arg AUTH_KEY="$(cat ssh_keys/pusheen-sshd.pub)" \
--tag your-tag-here .
FROM your-main-image
COPY docker/files/sshd_config docker/files/ssh-install.sh /root/
# SSHD key
ARG AUTH_KEY
RUN /root/ssh-install.sh
#!/usr/bin/env bash
# Setup OpenSSHd
echo "Configuring OpenSSH"
mkdir -p /root/.ssh
chmod 700 /root/.ssh
echo "${AUTH_KEY}" > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/*
chown -Rf root:root /root/.ssh
mkdir -p /var/run/sshd
mkdir -p /etc/ssh
mv /root/sshd_config /etc/ssh/sshd_config
apt-get -y install openssh-server
# Set this to some port that your setup doesn't use
Port 5022
ListenAddress 0.0.0.0
Protocol 2
PermitRootLogin without-password
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
Subsystem sftp internal-sftp
UsePAM yes
AllowTcpForwarding yes
# Fix for PyCharm remote debugger support
KexAlgorithms=diffie-hellman-group1-sha1
@grivescorbett
Copy link

What command do you use to run the docker container? I tried /usr/sbin/sshd but auth doesn't seem to be working.

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