Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create SSH server alias in Linux system

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to create a SSH server alias in the Linux system. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Create a SSH alias in Linux

Before I knew this trick, I usually used any of the following ways to connect to a remote system through SSH.

Use the IP address:

$ssh 192.168.225.22

Or use the port number, user name, and IP address:

$ssh-p 22 sk@192.168.225.22

Or use the port number, user name, 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 is the IP of my remote system

Server.example.com is the hostname of the remote system.

I believe that most Linux newcomers and (or some) administrators will connect to remote systems through SSH in this way. However, if you connect to multiple different systems through SSH, it is difficult to remember all hostnames or IP addresses, and user names, unless you write them on paper or save them in a text file. Don't worry! This can be easily solved by creating aliases (or shortcuts) for SSH connections.

We can create aliases for the SSH command in two ways.

Method 1-use SSH profile

This is my preferred way to create aliases.

We can use the SSH default configuration file to create SSH aliases. To do this, edit the ~ / .ssh/config file (if this file does not exist, just create one):

$vi ~ / .ssh/config

Add details for all remote hosts, as follows:

Host webserver

HostName 192.168.225.22

User sk

Host dns

HostName server.example.com

User root

Host dhcp

HostName 192.168.225.25

User ostechnix

Port 2233

Use the SSH configuration file to create a SSH alias in Linux

Replace the Host, Hostname, User, and Port configuration values with your own values. After you add the details of all remote hosts, save and exit the file.

Now you can enter the system through SSH using the following command:

$ssh webserver$ ssh dns$ ssh dhcp

It's that simple!

Look at the screenshot below.

Access remote systems using SSH aliases

You see that? I only use aliases (such as webserver) to access the remote system with the IP address 192.168.225.22.

Please note that this is only used by the current user. If you want to provide aliases for all users (system-wide), add the above line to the / etc/ssh/ssh_config file.

There are many other things you can add to the SSH configuration file. For example, if you have configured authentication based on SSH keys, explain the location of the SSH key file, as follows:

Host Ubuntu

HostName 192.168.225.50

User senthil

IdentityFIle / .ssh/id_rsa_remotesystem

Make sure that you have replaced the hostname, user name, and SSH key file path with your own values.

Now connect to the remote server using the following command:

$ssh ubuntu

In this way, you can add any number of remote hosts you want to access through SSH and quickly access them using aliases.

Method 2-use Bash alias

This is an emergency workaround for creating SSH aliases to speed up communication. You can use the alias command to make this task easier.

Open ~ / .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 the host, hostname, port number, and IP address with your own values. Save the file and exit.

Then use the command to apply the changes:

$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 through SSH. Use any of the above methods that suit you to quickly access remote Linux systems through SSH.

This is the end of the article on "how to create SSH server aliases in the Linux system". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report