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 aliases in Linux system

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces how to create SSH aliases in the Linux system, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

If you often access many different remote systems through SSH, this technique will save you some time. You can create SSH aliases for frequently visited systems through SSH, so you don't have to remember all the different user names, hostnames, SSH port numbers, IP addresses, and so on. In addition, it avoids repeatedly entering the same user name, hostname, IP address, and port number when SSH to the Linux server.

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, and 192.168.225.22 is the IP,server.example.com of my remote system 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 adds 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

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 ubuntuHostName 192.168.225.50User senthilIdentityFIle ~ /. 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' again ensures 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.

Recommended reading:

Allow or deny SSH access to specific users or groups in Linux how to SSH to a specific directory on Linux how to disconnect a SSH session in Linux 4 ways to keep commands running SSLH-share HTTPS and SSH on the same port after exiting a SSH session

Thank you for reading this article carefully. I hope the article "how to create SSH aliases in Linux system" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Development

Wechat

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

12
Report