Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#Generate root password
import random, string
password = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(20))
#Download ngrok
! wget -q -c -nc
! unzip -qq -n
#Setup sshd
! apt-get install -qq -o=Dpkg::Use-Pty=0 openssh-server pwgen > /dev/null
#Set root password
! echo root:$password | chpasswd
! mkdir -p /var/run/sshd
! echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
! echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
! echo "LD_LIBRARY_PATH=/usr/lib64-nvidia" >> /root/.bashrc
! echo "export LD_LIBRARY_PATH" >> /root/.bashrc
#Run sshd
get_ipython().system_raw('/usr/sbin/sshd -D &')
#Ask token
print("Copy authtoken from")
import getpass
authtoken = getpass.getpass()
#Create tunnel
get_ipython().system_raw('./ngrok authtoken $authtoken && ./ngrok tcp 22 &')
#Print root password
print("Root password: {}".format(password))
#Get public address
! curl -s http://localhost:4040/api/tunnels | python3 -c \
"import sys, json; print(json.load(sys.stdin)['tunnels'][0]['public_url'])"

This comment has been minimized.

Copy link

@StrangeTcy StrangeTcy commented Dec 29, 2018

This seems to fail on line 32 for me, when json.load() fails to parse sys.stdin


This comment has been minimized.

Copy link

@Goblin80 Goblin80 commented Feb 18, 2020

Is SSH tunneling possible?

Edit: Apparently yes.

In /etc/ssh/sshd_config, set GatewayPorts to yes.

Then using SSH escape sequence ~C, open a dynamic port.

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