Preface If you frequently access many different remote systems via SSH, this trick will save you some time. You can create SSH aliases for systems you frequently access through SSH so that you don't have to remember all the different usernames, hostnames, SSH port numbers, IP addresses, etc. Moreover, it avoids typing the same username, hostname, IP address, port number repeatedly when SSHing into a Linux server. Creating SSH Aliases in Linux Before I knew this trick, I usually used any of the following methods to connect to remote systems via SSH. Using IP Address: $ ssh 192.168.225.22 Or using port number, username, and IP address: $ ssh -p 22 [email protected] Or using port number, username, and hostname: $ ssh -p 22 [email protected] here
I believe that most Linux newbies and/or some administrators connect to remote systems via SSH in this manner. However, if you connect to many different systems via SSH, remembering all the hostnames or IP addresses, as well as usernames, can be difficult unless you write them down on paper or save them in a text file. don’t worry! This can be easily solved by creating an alias (or shortcut) for the SSH connection. We can create aliases for SSH commands in two ways. Method 1 – Using SSH Configuration File This is my preferred method of creating aliases. We can use the SSH default configuration file to create SSH aliases. To do this, edit the ~/.ssh/config file (if it doesn't exist, just create one): $ vi ~/.ssh/config Add the details of all remote hosts as shown below:
Creating SSH Aliases in Linux Using SSH Configuration File Replace the values for the Host, Hostname, User, and Port configurations with your own values. After adding the details of all the remote hosts, save and exit the file. Now you can SSH into the system using the following command: $ ssh webserver $ ssh dns $ ssh dhcp It's that simple! Take a look at the screenshots below. Accessing remote systems using SSH aliases Did you see it? I only use aliases (such as webserver) to access remote systems with IP address 192.168.225.22. Note that this only applies to the current user. If you want to provide alias for all users (system wide), add above line in /etc/ssh/ssh_config file. There are many other things you can add to your SSH configuration file. For example, if you have configured SSH key-based authentication, indicate the location of the SSH key file as follows:
Make sure to replace the hostname, username, and SSH key file path with your own values. Now connect to the remote server using the following command: $ ssh ubuntu This way, you can add as many remote hosts as you want to access via SSH and quickly access them using aliases. Method 2 – Using Bash Aliases This is a workaround to create an SSH alias to speed up communications. You can use the alias command to make this task easier. Open ~/.bashrc or ~/.bash_profile file: 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' Again, make sure you replace the host, hostname, port number, and IP address with your own values. Save the file and exit. Then, apply the changes using the command: $ source ~/.bashrc or $ source ~/.bash_profile In this method, you don't even need to use the ssh alias command. Instead, just use an alias as shown below. $ webserver $ dns $ dhcp $ ubuntu These two methods are very simple, but very useful and convenient for people who often connect to many different systems via SSH. Use any of the above methods that suits you to quickly access remote Linux systems through SSH. Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. You may also be interested in:
|
<<: React configuration px conversion rem method
Pitfalls encountered I spent the whole afternoon ...
Dockerfile is a text file used to build an image....
Docker officially recommends that we use port map...
Install postcss-pxtorem first: npm install postcs...
Introduction The module that limits the number of...
Use MySQL proxies_priv (simulated role) to implem...
Table of contents Scenario Requirements glibc ver...
The pop-up has nothing to do with whether your cur...
This article example shares the specific code of ...
Today I encountered a very strange situation. Aft...
Example Usage Copy code The code is as follows: &l...
CentOS 6 and earlier versions provide MySQL serve...
Effect If you use it, please optimize the code an...
I am planning to organize the company's inter...
When making a website, I found that video files, s...