.
Last active
February 13, 2021 23:26
-
-
Save Fusion/a81a6b5c90e40846e2f9f5ab03d41bc0 to your computer and use it in GitHub Desktop.
Temporarily run a lightweight SSH server in a docker container
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
[ "$C" == "" ] && { echo "Syntax: export C={containername} && curl ..."; exit 1; } | |
PORT="$(docker exec -t $C ps x | grep dropbear | grep -Po '(222[0-9]{2})')" \ | |
&& PID="$(docker exec -t $C cat /var/run/dropbear.pid)" | |
echo | |
echo yes | |
echo | |
echo "[$PID] [$PORT]" |
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
[ "$C" == "" ] && { echo "Syntax: export C={containername} && curl ..."; exit 1; } | |
P1=$(netstat -plnt 2>/dev/null | grep -Po '(222[0-9]{2})' | sort | tail -1) && P2=${P1:-22199} && PORT=$((P2 + 1)) \ | |
&& IP=$((docker exec -t $C ip addr) | grep -Po '(172\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})') | |
[ $? -ne 0 ] && { exit 1; } | |
while [ "$(docker exec -t $C ps aux | grep dropbear)" == "" ]; do | |
echo "Attempting to run dropbear"; docker exec -t $C dropbear -p $PORT; sleep 1 | |
done | |
[ $? -ne 0 ] && { exit 1; } | |
docker run -d --rm --name ssher-${PORT} -p ${PORT}:${PORT} svendowideit/ambassador ${IP} ${PORT} \ | |
&& echo "To terminate this SSH environment: export C={containername} && curl ..."; |
Or in ~/.ssh/config:
Host alias1 alias2 .. aliasn
HostName <ip or host name>
Port 22200 (or higher)
User root (or hopefully a less privileged user)
KexAlgorithms +diffie-hellman-group1-sha1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Your version of dropbear may be pretty old. Such is life with older containers. You may thus need to use your ssh client as follows: