Created
August 1, 2012 17:52
-
-
Save andrwj/3229239 to your computer and use it in GitHub Desktop.
connect remote ssh server easily.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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__} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// 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