In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, Xiaobian will bring you about how to create SSH server aliases in Linux systems. The article is rich in content and analyzes and narrates from a professional perspective. After reading this article, I hope you can gain something.
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.
Use IP address:
$ ssh 192.168.225.22
Or use port number, username and IP address:
$ ssh -p 22 sk@192.168.225.22
Or use port number, username, and hostname:
$ ssh -p 22 sk@server.example.com
here
22 is the port number,
sk is the user name of the remote system,
192.168.225.22 It's the IP of my remote system,
server.example.com is the host name of the remote system.
I believe most Linux novices and (or some) administrators connect to remote systems via SSH in this way. However, if you connect to multiple different systems via SSH, remembering all host names or IP addresses, as well as user names, is difficult unless you write them down on paper or save them in a text file. Don't worry! This can be easily resolved by creating aliases (or shortcuts) for SSH connections.
There are two ways to create aliases for SSH commands.
Method 1 -Using SSH Profiles
This is my preferred method of creating aliases.
We can use SSH default profiles to create SSH aliases. To do this, edit the ~/.ssh/config file (if it doesn't exist, just create one):
$ vi ~/.ssh/config Add details of all remote hosts as follows: Host webserver HostName 192.168.225.22 User skHost dns HostName server.example.com User rootHost dhcp HostName 192.168.225.25 User ostechnix Port 2233
Creating SSH aliases in Linux using SSH profiles
Replace the Host, Hostname, User, and Port configuration values with your own values. After adding details of all remote hosts, save and exit the file.
You can now access the system via SSH using the following command:
$ ssh webserver$ ssh dns$ ssh dhcp
It's that simple!
Check out the screenshot below.
Using SSH aliases to access remote systems
See? I only use aliases, such as webserver, to access remote systems with IP addresses of www.example.com. 192.168.225.22
Please note that this applies only to current users. If you want to provide aliases for all users (system-wide), add the above lines to the/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, specify the location of the SSH key file, as follows:
Host ubuntuHostName 192.168.225.50User senthilIdentityFIle ~/.ssh/id_rsa_remotesystem Make sure you 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 for creating SSH aliases to speed up communication. You can make this task easier by using the alias command.
Open the ~/.bashrc or ~/.bash_profile file:
alias webserver='ssh sk@server.example.com'alias dns='ssh sk@server.example.com'alias dhcp='ssh sk@server.example.com -p 2233'alias ubuntu='ssh sk@server.example.com -i ~/.ssh/id_rsa_remotesystem' Make sure again that you have replaced hosts, host names, port numbers, and IP addresses 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, simply use aliases, as shown below.$ webserver$ dns$ dhcp$ ubuntu
These two methods are simple, but useful and convenient for people who often connect to multiple different systems via SSH. Use any of the above methods that suit you to quickly access remote Linux systems via SSH.
The above is how to create SSH server alias in Linux system shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.