You can use the ssh client configuration file (.ssh/config
). If you have to type ssh -p 1234 mylogin@my.server.with.a.long.name.com
, you can populate your config file with
host server
hostname my.server.with.a.long.name.com
user mylogin
port 1234
Then you can simply type ssh server
and it will have the same effect. You can have as many entries in your .ssh/config
file as you want and even use wildcards (*
)
If you are using a recent version of bash, you can furthermore make use of the command_not_found_handle
function:
command_not_found_handle () {
if grep "host $1" ~/.ssh/config &>/dev/null; then
ssh $@
else
printf "Sorry: Command not found: $1\n"
return 127
fi
}
Then you can connect simply with
server