Skip to content

Instantly share code, notes, and snippets.

@kurahaupo
Created June 18, 2019 09:20
Show Gist options
  • Save kurahaupo/6ec05c8d9c94046acf5f16da1fd1775f to your computer and use it in GitHub Desktop.
Save kurahaupo/6ec05c8d9c94046acf5f16da1fd1775f to your computer and use it in GitHub Desktop.
write_key() {
mkdir -p "${JENKINS_AGENT_HOME}/.ssh"
echo "$1" > "${JENKINS_AGENT_HOME}/.ssh/authorized_keys"
chown -Rf jenkins:jenkins "${JENKINS_AGENT_HOME}/.ssh"
chmod 0700 -R "${JENKINS_AGENT_HOME}/.ssh"
}
if [[ $JENKINS_SLAVE_SSH_PUBKEY == ssh-* ]]; then
write_key "${JENKINS_SLAVE_SSH_PUBKEY}"
fi
if [[ $# -gt 0 ]]; then
if [[ $1 == ssh-* ]]; then
write_key "$1"
shift 1
else
exec "$@"
fi
fi
# ensure variables passed to docker container are also exposed to ssh sessions
env | grep _ >> /etc/environment
ssh-keygen -A
exec /usr/sbin/sshd -D -e "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment