How To Create SSH Alias In Linux


Get real time updates directly on you device, subscribe now.

If you happen to often entry loads of totally different distant programs by way of SSH, this trick will prevent a while. You’ll be able to create SSH alias to frequently-accessed programs by way of SSH. This fashion you needn’t to recollect all of the totally different usernames, hostnames, ssh port numbers and IP addresses and so forth. Moreover, It avoids the necessity to repetitively sort the identical username/hostname, ip handle, port no everytime you SSH right into a Linux server(s).

Create SSH Alias In Linux

Earlier than I do know this trick, normally, I hook up with a distant system over SSH utilizing anybody of the next methods.

Utilizing IP handle:

$ ssh

Or utilizing port quantity, username and IP handle:

$ ssh -p 22 [email protected]

Or utilizing port quantity, username and hostname:

$ ssh -p 22 [email protected]

Right here,

22 is the port quantity,
sk is the username of the distant system, is the IP of my distant system, is the hostname of distant system.

I imagine many of the beginner Linux customers and/or admins would SSH right into a distant system this fashion. Nonetheless, If you happen to SSH into a number of totally different programs, remembering all hostnames/ip addresses, usernames is bit tough until you write them down in a paper or save them in a textual content file. No worries! This may be simply solved by creating an alias(or shortcut) for SSH connections.

We are able to create an alias for SSH instructions in two strategies.

Technique 1 – Utilizing SSH Config File

That is my most popular means of making aliases.

We are able to use SSH default configuration file to create SSH alias. To take action, edit ~/.ssh/config file (If this file doesn’t exist, simply create one):

$ vi ~/.ssh/config

Add your whole distant hosts particulars like under:

Host webserver
Person sk

Host dns
Person root

Host dhcp
Person ostechnix
Port 2233
Create SSH Alias In Linux

Create SSH Alias In Linux Utilizing SSH Config File

Substitute the values of Host, Hostname, Person and Port with your personal. When you added the main points of all distant hosts, save and exit the file.

Now you’ll be able to SSH into the programs with instructions:

$ ssh webserver
$ ssh dns
$ ssh dhcp

It’s easy as that.

Take a look on the following screenshot.

create ssh alias

Entry distant system utilizing SSH alias

See? I solely used the alias title (i.e webserver) to entry my distant system that has IP handle

Please observe that this is applicable for present consumer solely. If you wish to make the aliases obtainable for all customers (system huge), add the above strains in /and so forth/ssh/ssh_config file.

It’s also possible to add loads of different issues within the SSH config file. For instance, you probably have configured SSH Key-based authentication, point out the SSH keyfile location as under.

Host ubuntu
Person senthil
IdentityFIle ~/.ssh/id_rsa_remotesystem

Ensure you have exchange the hostname, username and SSH keyfile path with your personal.

Now hook up with the distant server with command:

$ ssh ubuntu

This fashion you’ll be able to add as many as distant hosts you need to entry over SSH and rapidly entry them utilizing their alias title.

Technique 2 – Utilizing Bash aliases

That is fast and soiled solution to create SSH aliases for quicker communication. You should use the alias command to make this process a lot simpler.

Open ~/.bashrc or ~/.bash_profile file:

Add aliases for every SSH connections one after the other like under.

alias webserver=’ssh [email protected]’
alias dns=’ssh [email protected]’
alias dhcp=’ssh [email protected] -p 2233′
alias ubuntu=’ssh [email protected] -i ~/.ssh/id_rsa_remotesystem’

Once more be sure you have changed the host, hostname, port quantity and ip handle with your personal. Save the file and exit.

Then, apply the modifications utilizing command:

$ supply ~/.bashrc


$ supply ~/.bash_profile

On this methodology, you don’t even want to make use of “ssh alias-name” command. As a substitute, simply use alias title solely like under.

$ webserver
$ dns
$ dhcp
$ ubuntu

create ssh alias 1

These two strategies are quite simple, but helpful and far more handy for individuals who typically SSH into a number of totally different programs. Use any one of many aforementioned strategies that fits so that you can rapidly entry your distant Linux programs over SSH.

Recommended learn:

And, that’s all for now. Hope this was helpful. Extra good stuffs to return. Keep tuned!


Thanks for stopping by!

Assist us that will help you:

Have a Good day!!

Source link

Leave A Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More