Created
April 6, 2023 17:08
-
-
Save BlackthornYugen/7e0f71dd7fc33fc5193c1b3de47ab584 to your computer and use it in GitHub Desktop.
ssh jumpbox with gpg agent and random password
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
FROM --platform=linux/arm64 amazonlinux:2 | |
RUN yum install -y openssh-server | |
RUN useradd -ms /bin/bash jumpuser | |
RUN mkdir -v /run/sshd | |
RUN ssh-keygen -A | |
USER jumpuser | |
RUN mkdir ~/.gnupg ~/.ssh | |
RUN echo 'eval `ssh-agent -s` > /dev/null' >> ~/.bashrc | |
RUN echo 'export SSH_AUTH_SOCK=$HOME/S.gpg-agent.ssh' >> ~/.bashrc | |
USER root | |
COPY entrypoint.sh / | |
ENTRYPOINT [ "/entrypoint.sh" ] |
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
#!/usr/bin/env bash | |
random_password() { | |
echo -n "jumpuser password: " > /dev/stderr | |
dd if=/dev/random count=$(($1 * 2)) bs=1 2> /dev/null | base64 | tr -d '/=+' | head -c "$1" | tee /dev/stderr | |
echo > /dev/stderr | |
} | |
chpasswd <<< "jumpuser:$(random_password 32)" | |
while sleep 3 ; do | |
/usr/sbin/sshd -D -p 22 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment