🕹ī¸ Do Something Great! 😄

Tag: ssh

  • Uploading my current IP address so I can find my Pi

    For some reason my autossh job is failing to set up the reverse tunnel so I can find and connect to my Pi when the Pi is roaming. Until I figure out why that is happening, I wrote this bash script which will upload the wifi interface’s current IP address to a remote server.

    1
    2
    3
    4
    #!/bin/bash
    
    echo `ifconfig wlan0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'` | \
        ssh [email protected] "cat > ~/myip.txt"
    

    I already have ssh passwordless logins in set up because of autossh. If you don’t have that set up, then you’ll need to do that first or this won’t work. I then add a cron job to run this script every minute.

  • Jumping to multiple hosts with ssh behind a gateway

    At home I have several hosts that I need to ssh into at various times. Unfortunately, since IPv6 is widely deployed, I am stuck sshing into one host that is publically accessible, and from there sshing into other hosts. Cumbersome to say the least, but it does look cool when I’m showing it off.

    Anyway, you can automate the connection with netcat on the gateway host. I like to put my ssh commands into my ~/.ssh/config file so then I don’t have to remember anything. To jump to an internal host from the gateway I add the following to my ~/.ssh/config file on the client (most notably, my 2010 MacBook Pro).

    Host macmini
        hostname LOCALIP
        user gadmin
        ProxyCommand ssh USER@GATEWAY nc %h %p
    

    Replace LOCALIP with the address of the host to which you want to jump, and replace USER@GATEWAY with the gateway’s username and address. You can use other hosts defined in your ~/.ssh/config file, so if you have a host for GATEWAY, you can use it.