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 use rsa password-free login for ssh in linux

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains the "linux ssh how to use rsa password-free login", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "linux ssh how to use rsa password-free login" bar!

An is the local host (that is, the machine used to control other hosts)

B is the remote host (that is, the controlled machine Server), if the ip is 172.24.253.2

The command on A:

The code is as follows:

Ssh-keygen-t rsa

(enter for three times in a row, that is, the public key and private key are generated locally, and the password is not set. The generated public key and private key are in the ~ / .ssh directory. Id_rsa is the private key and id_rsa.pub is the public key.)

The code is as follows:

Ssh muye@172.24.253.2

Mkdir .ssh

Chmod 700 .ssh

(password is required. Note: permissions for .ssh must be set to 700)

The code is as follows:

Scp / .ssh/id_rsa.pub muye@172.24.253.2:~/.ssh

Then create the authorized_keys file on the server:

The code is as follows:

Touch / .ssh/authorized_keys

Chmod 600 ~ / .ssh/authorized_keys

(note: the permission of ~ / .ssh/authorized_keys must be changed to 600. this file is used to save the public key generated by the ssh client. You can change the server's ssh server configuration file / etc/ssh/sshd_config to change the file name. The default is authorized_keys)

The code is as follows:

Cat id_rsa.pub > > authorized_keys

# (append the contents of id_rsa.pub to authorized_keys, be careful not to use >, otherwise the original content will be emptied and others will not be able to log in with the original key)

Go back to machine A:

The code is as follows:

# ssh muye@172.24.253.2 (No password required, login is successful)

A simple understanding of the login process from the surface

First, the ssh-keygen-t rsa command generates a key and a public key, and the key can set its own password

The key can be understood as a key, and the public key as the lock corresponding to the key.

Put the lock (public key) on the server you want to control and lock the server. Only the person who has the key (key) can open the lock, enter the server and control it.

For the person who owns the key, it is necessary to know the password of the key itself in order to use the key (unless the key has no password), so as to prevent the key from being matched (the private key is copied).

In a more concise way:

Step 1. If there is no authorized_keys file on the server, then: (skip this step if so)

The code is as follows:

Ssh muye@172.24.253.2

Mkdir .ssh

Chmod 700 .ssh

Touch / .ssh/authorized_keys

Chmod 600 ~ / .ssh/authorized_keys

Step 2, on the local machine:

The code is as follows:

Ssh-keygen-t rsa

Ssh-copy-id-I / .ssh/id_rsa.pub muye@172.24.253.2

Enter three times after ssh-keygen-t rsa #, indicating no password. That's it.

Note: ssh-copy-id automatically appends the key to .ssh / authorized_key of the remote host

Thank you for your reading, the above is the content of "ssh in linux how to use rsa password-free login". After the study of this article, I believe you have a deeper understanding of how ssh in linux uses rsa password-free login, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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