Eight tips for using OpenSSH in Ubuntu

Source: Internet
Author: User

After coming to Ubuntu, the "efficient" office habits accumulated in windows have to be rewritten. The first thing is remote server management. The main character of today is the OpenSSH-client that will be released along with OpenSSH-server. If openssh-server is not installed by default, most releases will also integrate this feature by default. I used to remotely log on to Linux and often use SSH commands to connect to other machines, however, most of the things mentioned today are only known after I use ubuntu. What kind of energy does this unpretentious little Dongdong have? I will share with you the following small desserts:

1. Private Key Login

No matter which client software you use, the key option is set, and the SSH command is no exception. By default, ssh reads the id_rsa file in. SSH in the user's home directory. Here is an episode: My original key was generated using securecrt. When saving, the system will prompt whether the private format of securecrt is used or the OpenSSH format is used. I used the securecrt format at that time. After I put it in this directory, you may be worried. Later, securecrt was used to re-save it to the OpenSSH format (re-save is not a re-generate process. If there are so many servers that need to be re-saved one by one, there will be no re-generate desire ). Note that the id_rsa file name must be the same. Otherwise, you will not know the cause of the Emergency (of course, when you learn how to use the configuration file later, you will also know the identity and id_dsa, And what names you want to use at that time will follow your mind ). In addition, the permission for this file is 600. Otherwise, SSH will not buy accounts.

2. Specify the user name

Everyone will have their favorite user names, like the author would like to use Rainbird, so when I log on to the system, the user name is also Rainbird. The server you connect to does not determine your current user name, and then creates an account for you. By default, "ssh IP" is used. SSH determines whether you have a configuration file to specify the Default User Name. If not, it determines whether you have used the format of SSH-l Rainbird IP or SSH Rainbird @ IP in the command, if no, it will take the username you logged on to the current system by default. To connect to a remote system. If the user you connect to uses the same username instead of the "Rainbird", for example, "root", is it annoying to enter the "-l" or "user @ IP" format every time? The more input, the lower the efficiency. As mentioned above, SSH will first determine whether a configuration file exists.

I learned that SSH will read two configuration files: one is ~ /. Ssh/config. If no, the system reads/etc/ssh/ssh_config. This is also the work philosophy of Linux: Every user will have their own personalized configuration files, so the user will use a unified configuration file by default. With the idea of trying it out, the author VI ~ /. Ssh/config. When the user is written, the description is highlighted. It seems to be the description, so the data is written as follows:

User Root

After saving and exiting, when I try to access the ssh ip address, I find that the connection is actually in the form of root @ IP:

[Rainbird @ Rainbird ~] $ SSH 192.168.5.18

Root@192.168.5.18's password:

3. Specify the connection port and password

After setting the user name for the default connection, I have tasted the sweetness. So I began to carefully study the configuration file/etc/ssh/ssh_config. I used to only know that there was such a file, but I did not read it carefully. This research does not matter, and many problems have been solved. The first two lines that attract my attention are:

# Port 22

# Protocol 1, 2

The two lines mean that the default connection port is 22, and the default connection uses SSH protocol 1 and 2. Open directly ~ /. Ssh/config also adds the two rows:

Port 1222

Protocol 2

Does it save a lot of things?

4. Add accessible host names

Strictly speaking, this is not unique to SSH commands. No matter which client software is used, the session saving function is available. But does the SSH command read the default session configuration function? I also thought for a long time, but did not find a solution. In fact, I think ssh xxx. XXX is a little tired every time, mainly because I don't catch a cold on numbers. What should we do? The boss said, you just need to use the domain name directly? Hmm? The domain name is easy to remember, but it is easy to remember. What should I do? Write hosts directly! The reason is that hosts is not enough. When hosts is enough, why not use hosts? Besides, it not only saves time for parsing once and for all, but also saves two birds in one fell swoop. Sudo
VI/etc/hosts

XXX. XXX Web

When you access the Web later, you can directly access the Web through SSH. Well, it is a bit in line with the concise and efficient idea of Linux.

5. Ssh Chinese garbled characters

The world is beautiful. Rich and colorful. The problem of normal Chinese display in Linux has always been my biggest concern. Chinese characters are garbled when you use SSH to log on to a Linux server in a Chinese environment. What should we do? Can this problem be solved? The answer is yes. There is such a sentence in/etc/ssh/ssh_config:

Sendenv Lang lc_all

This option is enabled by default, meaning the sending system language environment. The Internet says sendenv lang = en. US.UTF-8 lc_all = en. US.UTF-8 can be written. However, according to my understanding: When lc_all is set, even if Lang is set, it must be subject to lc_all ~ /. Ssh/config adds the following sentence:

Sendenv Lang lc_all = en. US.UTF-8

Haha, Chinese is displayed correctly. A wonderful life!

6. enable SSH key forwarding on the SSH client

In Linux, there is an automatic key forwarding function. You can use the private key of your local machine for automatic verification when you remotely connect to a Linux instance and then SSH to other machines, greatly improve work efficiency and security. Can this function be implemented using common SSH commands? The answer is yes! However, we need to take two steps. First, VI ~ /. Add ssh/config:

Forwardagent Yes

Then execute the command: SSH-add

It will default ~ /. Ssh/id_rsa is added to your transit proxy. Wow Kaka, I have Hu hansan back

7. Prevent disconnection

For the sake of security and resource saving, the SSH server will automatically disconnect idle sessions for a period of time. It is easy to connect to a machine after the previous transformation. However, it is really uncomfortable to log on again when you get out and smoke a cigarette. What should we do? As the saying goes: there are policies and countermeasures.

VI ~ /. Ssh/config

Serveraliveinterval = 60

In this way, is the server very good.

8. No regrets

I still remember <Linux Remote Management's tu longdao (ultimate article)> I mentioned that garbled characters may occur when I use a graphic tool on the Character interface? I was pleasantly surprised to find that this problem did not exist when I used the OpenSSH client tool!

Why? How is Ubuntu able to support Chinese environments? Because gnome terminal 2.28.1 is used? Is utf8 supported by SSH enabled? I don't want to investigate the cause, because I already like ubuntu.

From: http://rainbird.blog.51cto.com/211214/248225

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.