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 realize SSH password-free login to remote server in Linux system

2025-03-01 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 achieve SSH password-free login to the remote server in 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.

To build a Hadoop environment, you need to set up password-free login. The so-called password-free login actually refers to logging in through certificate authentication and using a way called "public and private key" authentication to log in to ssh. In linux systems, ssh is the default tool for remote login because its protocol uses RSA/DSA 's encryption algorithm. It is very safe for this tool to do remote management of linux system. Telnet, because of its insecurity, has been shelved in linux systems.

The "public and private key" authentication method is simply explained as follows: first, create a pair of public and private keys on the client (public key file: ~ / .ssh/id_rsa.pub; private key file: ~ / .ssh/id_rsa). Then put the public key on the server (~ / .ssh/authorized_keys) and keep the private key for yourself. When logging in using ssh, the ssh program sends the private key to match the public key on the server. If the match is successful, you can log in.

1. Confirm that SSH has been installed on the system.

Rpm-qa | grep openssh

Rpm-qa | grep rsync

-- > the following information appears to indicate that it has been installed

Assuming that ssh and rsync are not installed, you can install them with the following command.

Yum install ssh-- > install the SSH protocol

Yum install rsync-- > rsync is a remote data synchronization tool that allows you to quickly synchronize files between multiple hosts through LAN/WAN

Service sshd restart-- > start the service

2. Generate a secret key pair

Ssh-keygen-t rsa-P''--> key pairs generated directly by enter: id_rsa and id_rsa.pub, which are stored in the "/ home/hadoop/.ssh" directory by default.

3. Append id_rsa.pub to the authorized key.

Cat ~ / .ssh/id_rsa.pub > > ~ / .ssh/authorized_keys

4. Modify the permissions of the authorized key

Chmod 600 ~ / .ssh/authorized_keys

5. Modify SSH configuration file

Su-- > Log in to root to modify the configuration file

Vim / etc/ssh/sshd_config-- > remove the comments from the three lines in the following figure

6. Test the connection

Service sshd restart-- > restart the ssh service

Exit-- > quit the root user and return to the normal user

Ssh localhost-- > connection test for ordinary users

This is just to configure the SSH service on the stand-alone environment, to connect to other servers remotely, and then see below.

7. Now that the key pair has been generated and the client SSH service has been configured, send our key (public key) to the server.

Scp ~ / .ssh/id_rsa.pub remote user name @ remote server IP:~/-- > copy the public key to the remote server's ~ / directory

For example, scp ~ / .ssh/id_rsa.pub hadoop@192.168.1.134:~/

You can see that when we copy, we need to enter the password of the server, and after we have configured the SSH, these steps do not have to enter the password.

8 、

In the previous step, the public key was sent to the 192.168.1.134 server, and we went to the 134 machine to append the public key to the authorized key.

Note: if you are running SSH for the first time, the .ssh directory needs to be created manually, or use the command ssh-keygen-t rsa to generate the secret key, which automatically generates the .ssh directory under the user directory. Pay special attention to the permissions of the .ssh directory. Remember to run the chmod 700.ssh command.

Use the command: cat ~ / id_rsa.pub > > ~ / .ssh/authorized_keys-- > append the public key to the authorized key rm ~ / id_rsa.pub-- > to be on the safe side, delete the public key also repeat steps 4 and 5 on the machine, service sshd restart--

In the previous step, the public key was sent to the 192.168.1.134 server, and we went to the 134 machine to append the public key to the authorized key.

Note: if you are running SSH for the first time, the .ssh directory needs to be created manually, or use the command ssh-keygen-t rsa to generate the secret key, which automatically generates the .ssh directory under the user directory. Pay special attention to the permissions of the .ssh directory. Remember to run the chmod 700.ssh command.

Use the command: cat ~ / id_rsa.pub > > ~ / .ssh/authorized_keys-- > append the public key to the authorized key rm ~ / id_rsa.pub-- > to be on the safe side, delete the public key and repeat steps 4 and 5, service sshd restart-- > restart the ssh service

Restart the ssh service

9 、

Back to the client, type: ssh 192.168.1.134-- > and you should be able to connect directly to the server.

Back to the client, type: ssh 192.168.1.134-- > and you should be able to connect directly to the server.

On "Linux system how to achieve SSH password-free login remote server" this article is shared here, 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