Log in to the server using SSH

Source: Internet
Author: User
Tags ssh config

Work, you need to log on to the development machine often, we enter the general

1 SSH [Email protected]

After that, you will be prompted to enter a password to complete the login.

Each time I input so much, too much trouble, I use the following methods to quickly and easily login:

The first step is to omit the input password operation, as follows:

Use Ssh-keygen to generate a pair of public and private keys on your own machine

1 Ssh-keygen ' Your email address '

As prompted, ~/.ssh/id_rsa is generated by default, ~/.ssh/id_rsa.pub

Then we need to add the public key id_rsa.pub to the server's Authorized_keys, so that the password can be free to login.

Use the old ways to log on to the server , the following operations on the server

1 cd ~/. SSH 2 Vim Authorized_keys

Attach the id_rsa.pub content generated on the local machine to the server after the Authorized_key file (if the original file has content), save.

Here, you also need to pay attention to the server. SSH folder and Authorized_key this file access rights.

1 chmod  - Authorized_keys 2 chmod  . SSH

All OK, now using SSH [email protected], do not need to enter a password, directly landed in!

The second step, save the input [email protected], this step on the local machine operation

There are many ways to add alias in. BASHRC, or you can write a. sh script file and execute the file.

But here, I use the SSH config method to do this. Specific as follows

1 cd ~/. SSH 2 vim config

In the config file, add the following code

1 Host Dev 2     hostname example.com 3     User username

Now try it on the console.

1 ssh Dev

You can go directly to the landing!

Because the first step above, we add their own public key in the server's Authorized_keys, so landing is very convenient, but sometimes, we do not have the authority to do this thing, such as Landing company relay machine, or to enter the password. A console is not enough, we want to open a new console tab (such as I use Iterm, command+t), this time we in the new window SSH login, and prompted to enter the password, very annoying. The following method can be solved!

On the local machine, or open the. ssh/config file, add the following lines

1 Host *2     controlpath ~/.  SSH/master-%[email protected]%h:%p3     controlmaster Auto

In this way, we see that when the server is first connected, an [email protected]:p ORT file is generated under. SSH, and after that the same new connection is shared, and no password is required.

After these configurations, is it more convenient to log in now?

Log in to the server using SSH

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.