Command Line Shortcut for Lengthy SSH Commands
We love tips that make your computing life easier, and this command line tip from Cedrik Morgan falls into that category, making a lengthy ssh command quite a bit shorter by creation of an alias.
Here’s what Cedrik writes in:
“If you have a server that you commonly access a nice way to avoid typing a lengthy command like ‘ssh 192.168.1.100 -l admin’ over and over again is to create an alias in your .profile, here’s how to set it up:
From the command line use a text editor, I’ll suggest nano because it’s easy to use, type:
and add the following line to your .profile:
alias servername="ssh serverIP.com -l username -p port"
nNow instead of typing out the ful ‘ssh serverIP blah blah’ command, you can just type servername, much easier! “
Thanks Cedrik! And yes, you can add a password to the ssh shortcut if desired, but that’s not recommended since it would be stored in plain text within the profile or .bash_profile document.
We’ve covered the alias command a bit in the past with the article titled Launching GUI Applications from the Terminal, check it out for more info and another example of using an alias for shorthanding a lengthy command line trick.
Got any other tips for ssh or shortcuts for remote logins? Let us know in the comments!