Skip to content

Instantly share code, notes, and snippets.

@andrwj
Created August 1, 2012 17:52
Show Gist options
  • Save andrwj/3229239 to your computer and use it in GitHub Desktop.
Save andrwj/3229239 to your computer and use it in GitHub Desktop.
connect remote ssh server easily.
#!/bin/bash
# if $0 looks like id@domain
# then login as id
# else
# login as default user
__DEFAULT_SSH_LOGIN_UID__="root"
__self__="`basename $0`"
__tmp__="`mktemp -t uid`"
echo $__self__ | awk 'BEGIN { FS = "@" } ; { print $1 }' > $__tmp__
__uid__="`cat $__tmp__`"
if [[ "$__uid__" == "" ]]; then
__uid__=${__DEFAULT_SSH_LOGIN_UID__}
fi
echo $__self__ | awk 'BEGIN { FS = "@" } ; { print $2 }' > $__tmp__
__host__="`cat $__tmp__`"
rm -f $__tmp__
ssh -l ${__uid__} ${__host__}
@andrwj
Copy link
Author

andrwj commented Aug 1, 2012

// To be more lazy man, I alway using this script for connecting remote ssh server.
// make symbolic link your favorites as filename to this "connect.ssh" script.
// and then just enter the symlinked filename to connect ;-)
// don't forget to place this script in your PATH.

$ chmod +x connect.ssh
$ ln -s connect.ssh [email protected]
$ ln -s connect.ssh [email protected]
$ ln -s connect.ssh the.other.host

$ ./[email protected] # same as ssh -l some-id-01 some.host
$ ./[email protected] # same as ssh -l some-id-02 other.host
$ ./the.other.host # same as ssh -l root the.other.host

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