How to use ssh aliases in command line

Publié le par vincent

Over the projects pile up servers, with them their access. Concerned about the safety of its application, the client often requires us restricted access by a range of options: extended username and password, specific port, VPN access, photo ID, digital control, checking DNAai??i??

So I decided to simplify my life withai??i?? « alias ssh » (tadaaaaaa). Very easy to proceed: just create the file ~/.ssh/config, and store all your information as following:

Host nickname
HostName hostname_or_ip
Port port_number
User username

You can now connect to your server through the following command:
$ ssh nickname

You agree that, for security reasons, the password should never be stored in this file. Now, you configure a « RSA key » ;) .

« Ah, it’s so cool! Butai??i?? when I type ‘ssh <tab> <tab>’, I don’t have any autocomplete?! »

Do not go too fast Hermes, one thing at a time. There is a tool for Linux and OSX improving it: bash-completion. Install it as follows, depending on your system:

$ apt-get install bash-completion
$ brew install bash-completion
$ yum install bash-completion

Finally, follow the directions by adding the following code in your ~/.bash_profile file (or ~/.bashrc):

if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion

If you run the command ‘ssh ni<tab> <tab>‘, the terminal will now propose known hosts in your system, recorded either in your ~/.ssh/config file or in the known hosts (~/.ssh/known_hosts).

Cette entrée a été publiée dans Bash tools, avec comme mot(s)-clef(s) , . Vous pouvez la mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *


* three = 3

Vous pouvez utiliser ces balises et attributs HTML : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>