Skip to content

Instantly share code, notes, and snippets.

@s1113950
Created March 17, 2018 00:02
Show Gist options
  • Save s1113950/0d7cfe3fc88329c4b4ae0cb75750e8aa to your computer and use it in GitHub Desktop.
Save s1113950/0d7cfe3fc88329c4b4ae0cb75750e8aa to your computer and use it in GitHub Desktop.
Installs ssh into container, can be used to patch kubernetes pod
# RUN LIKE THIS:
# kubectl cp "install_ssh.sh" "${pod}":/tmp/install_ssh.sh
# kubectl exec -i "${pod}" -- /tmp/install_ssh.sh
#!/bin/bash
if ! [ -d /etc/apt ]; then
echo "This container OS is not supported"
exit 1
fi
if [[ $(dpkg-query -W -f='${Status}' openssh-server 2>/dev/null | grep -c "ok installed") -eq 0 ]]; then
apt-get update && apt-get install -y --no-install-recommends openssh-server
fi
apt-get update && apt-get install -y vim
mkdir -p /var/run/sshd
chown root:root "${HOME}"/.ssh/authorized_keys*
chmod 0600 "${HOME}"/.ssh/authorized_keys*
sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
service ssh start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment