Skip to content

Instantly share code, notes, and snippets.

@MarioRicalde
Last active August 29, 2015 13:56
Show Gist options
  • Save MarioRicalde/8965039 to your computer and use it in GitHub Desktop.
Save MarioRicalde/8965039 to your computer and use it in GitHub Desktop.
SSH Change to Directory
# SSH Change Directory
function sshcd() {
port=""
getopts ":p:" opt;
if [ ! -z $OPTARG ]; then
port="-p $OPTARG"
shift 2
fi
eval "ssh $1 $port -t 'cd $2 && exec \$SHELL'"
}

Usage

Common:

sshcd user@server.tld /var/www

With a Port:

sshcd -p 2200 user@server.tld /var/www
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment