So that your computer can connect to Raspberry Pi without entering a password. You only need to generate an SSH key.
1. Check for existing SSH keys (check the existing SSK key)
First, check whether your computer (the device you use to connect to Raspberry Pi) has an SSH key:
ls ~/.ssh
If you see
Id_rsa.pubOr
Id_dsa.pubThen you have configured the key. You can skip the key generation step (or use
Rm ID *Command to delete these files, and then regenerate the key ).
2. geneerate new SSH keys (generate a new SSH key)
To generate a new SSH key, enter the following command (<Your name >@< your device>"The recognizable host name. Here we use [email protected]):
ssh-keygen -t rsa -C [email protected]
You can also use quotation marks to add more detailed descriptions with spaces, suchSsh-keygen-t rsa-c "Raspberry Pi #123".
After the preceding command is entered, you must enter the location where the key is saved. We recommend that you press enter to use the default path (/home/XXX/. Ssh/id_rsa ).
You will also be asked to enter a password. This is an additional security guarantee that your key cannot be used without your password. In this way, even if someone copies your key, they cannot impersonate you for access. If you want to use a password, enter the password, press enter, and then enter the password again as prompted. If you press enter without entering anything, the password is not used.
Now you should be able to see files such as id_ras and id_ras.pub in the. Ssh folder in your home directory:
ls ~/.sshauthorized_keys id_rsa id_rsa.pub known_hosts
HereId_rsaThe file is your private key, which is saved on your computer.Id_rsa.pubThe file is your public key and you need to put it on the device you want to connect. When the device you want to connect to matches your public key and private key, it will allow you to access.
Run the following command to view your public key:
cat ~/.ssh/id_rsa.pub
The Public Key format should be as follows:
ssh-rsa <REALLY LONG STRING OF RANDOM CHARACTERS> [email protected]
3. Copy your public key to your Raspberry Pi (copy your public key to your Raspberry Pi)
Copy your public key to your Raspberry Pi and use the following command on your computer terminal to attach the public key to your Raspberry PiAuthorized_keysFile, sent via SSH (replace username and IP-ADDRESS with the username and Raspberry Pi IP on Raspberry Pi ):
cat ~/.ssh/id_rsa.pub | ssh <USERNAME>@<IP-ADDRESS> 'cat >> .ssh/authorized_keys'
Note that you still need to verify your password this time.
Try nowSSH <user >@< IP-ADDRESS>Command, you should be able to connect directly without a password.
If you see the "agent admitted failure to sign using the key" information, you need to add your RSA or dsa id to the Authentication Proxy, and run the following command to use SSH-AGENT:
ssh-add
If this still does not work, useRm ~ /. Ssh/ID *Command to delete your key and reconfigure it according to this document.
To send files through SSH, you can also use the SCP command (secure replication ). For more information, see the SCP guide.
Pay: SCP guide --
SCP is a command to send files through SSH. This means you can send files between two computers, that is, you can send files between your Raspberry Pi and your desktop or notebook.
Address: http://www.raspberrypi.org/documentation/remote-access/ssh/passwordless.md
Access Raspberry Pi Using SSH password-less Authentication