Connect to the server without a password, use the .pem certificate file (key) to connect to the server.
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 certificateThen 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.Testmv 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]
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!