Skip to content

Instantly share code, notes, and snippets.

@alecdwm
Created March 12, 2018 03:50
Show Gist options
  • Select an option

  • Save alecdwm/31c9719f1670209939b02ca6fb9dbfba to your computer and use it in GitHub Desktop.

Select an option

Save alecdwm/31c9719f1670209939b02ca6fb9dbfba to your computer and use it in GitHub Desktop.
My preferred method of connecting to personal servers
# On the first attempted connection since an ssh-agent restart,
# you will be prompted for your ssh key's passphrase.
#
# On the first attempted connection since a server restart,
# a new tmux session will be created.
#
# On subsequent connections, the existing tmux session will
# be used.
#
# Usage:
# # copy script
# $ cp server_name.sh <remote-server-name>
# # set SERVER_HOSTNAME env var
# # (literally put the characters <remote-server-name> into the sed expression)
# $ sed -ie 's/<remote-server-name>/owls.io/g' <remote-server-name>
# # connect to server
# $ <remote-server-name>
export SERVER_HOSTNAME="<remote-server-name>"
export SSH_PRIVKEY="${HOME}/.ssh/${SERVER_HOSTNAME}_id_rsa"
export TMUX_SESSION_NAME=$(echo $SERVER_HOSTNAME | sed -e 's/\.//g')
ssh-add -l | grep "$SSH_PRIVKEY" >/dev/null 2>&1 || ssh-add "$SSH_PRIVKEY"
mosh "$SERVER_HOSTNAME" --server "LANG=$LANG mosh-server" -- tmux -2 new -A -s "$TMUX_SESSION_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment