Skip to content

Instantly share code, notes, and snippets.

@dafta
Last active October 11, 2020 14:47
Show Gist options
  • Save dafta/26bec7ade1ca299926b5bc47064aeed0 to your computer and use it in GitHub Desktop.
Save dafta/26bec7ade1ca299926b5bc47064aeed0 to your computer and use it in GitHub Desktop.
ssh with .ssh/sshrc forwarding
# Forwarding your .ssh/sshrc file and sourcing it as .bashrc
# A function sudoi is defined on the remote machine, used
# instead of sudo -i, to run a shell as the specified user,
# or root as default, and source the local .ssh/sshrc.
function ssh() {
tmprc=$(/usr/bin/ssh "$@" "mktemp" 2>/dev/null)
rsync ~/.ssh/sshrc "$1:$tmprc" >/dev/null 2>&1
echo "function sudoi() { sudo -u \"\${1:-root}\" bash --rcfile \"$tmprc\"; }" | /usr/bin/ssh "$@" "cat - >> \"$tmprc\"" >/dev/null 2>&1
/usr/bin/ssh -t "$@" "chmod a+r \"$tmprc\"; bash --rcfile \"$tmprc\" ; rm \"$tmprc\""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment