Home > System Tutorial > LINUX > body text

Server connection via key

WBOY
Release: 2024-01-30 17:12:22
forward
1136 people have browsed it

Connect to the server without a password, use the .pem certificate file (key) to connect to the server.
Server connection via key

1. Generate key file

ssh-keygen -t rsa -b 2048 -v
Note: The connection method is basically the same as that of Git. If you have previously generated public keys and secret keys for authentication with Git, please use the default path ~/.ssh/id_rsa. Be careful to switch paths. , name to avoid overwriting effects. For example:
Generating public/private rsa key pair.<br> Enter file in which to save the key (/home/vien/.ssh/id_rsa): dataAutoProcess

Specify the file name. If the path is not specified, the current path is used by default. As shown in the above prompt message, the key name generated in the current directory is dataAutoProcess, the public key name is dataAutoProcess.pub, and the rest is OK by pressing Enter.

2.Add this certificate

Then go to the directory where you generated the public key and push the public key to the remote server so that it can add this certificate.
ssh-copy-id -i dataAutoProcess.pub [email protected]

Replace dataAutoProcess.pub with your public key name, [email protected] with your server username and address, and then enter the password.

3.Test

mv dataAutoProcess dataAutoProcess.pem # You can change the name of your key, of course you can leave it unchanged<br> ssh -i dataAutoProcess.pem [email protected]

4. Cancel password login

After you test that your key can be logged in, make sure you can connect and cancel the password login method.
sudo vim /etc/ssh/sshd_config
After entering the vim editor, press / to enter the search mode, then paste PasswordAuthentication , press Enter and locate here, press i to enter the insert mode, release the comment, and change it to no.
# PasswordAuthentication yes
Change to
PasswordAuthentication no
Restartssh
sudo service ssh restart

The above is the detailed content of Server connection via key. For more information, please follow other related articles on the PHP Chinese website!

source:linuxprobe.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!