-
According to the previous article, the public key has been uploaded remotely. Now I need to delete it so that I can better test the remote copy.
// Login phone dengzemiaodemacbook-pro :~ dengzemiao$SSH [email protected] // go to ~/. SSH folder iPhone:~ root# CD ~/ IPhone :~/. SSH root# ls -l total 4 -rw------- 1 root wheel 403 Dec 8 17:49 authorized_keys // Remove authorized_keys uploaded previously SSH root# rm authorized_keys :~/. SSH root# exit logout Connection to 10.0.89.184 closedCopy the code
-
Generate public and private key folders before the client finds them
$ cd ~/.ssh Copy the code
dengzemiaodeMacBook-Pro:~ dengzemiao$ cd ~/.ssh dengzemiaodeMacBook-Pro:.ssh dengzemiao$ ls -l total 24 -rw------- 1 dengzemiao staff 1679 12 4 2018 id_rsa -rw-r--r-- 1 dengzemiao staff 403 12 4 2018 id_rsa.pub -rw-r--r-- 1 dengzemiao staff 2190 12 7 11:31 known_hosts dengzemiaodeMacBook-Pro:.ssh dengzemiao$ Copy the code
-
Then run the SCP client file address root@server IP address: Server storage file address command to remote copy the file
$SCP ~ /. SSH/id_rsa. Pub [email protected]: ~ /. SSHCopy the code
SSH /id_rsa.pub on the client to ~/. SSH on the [email protected] server.
SSH :~/. SSH /id_rsa.pub [email protected]:~/. SSH // Because we above the first step to delete the previous authorization file, so now there is no secret login [email protected]'s password: Id_rsa. pub 100% 403 10.1KB/s 00:00 dengzemiaodeMacBook-Pro:. SSH Dengzemiao $Copy the code
After the copy is successful, log in to the server to check whether the ~/. SSH folder contains the id_rsa.pub file.
SSH dengzemiao$SSH [email protected] // Enter password [email protected]'s password: SSH iPhone:~/. SSH root# ls -l total 4 -rw-r--r-- 1 root wheel 403 Dec 9 11:40 id_rsa.pubCopy the code
-
Now that the file has been copied remotely, we need to append the public key information to the end of the authorized_keys file.
$ cat id_rsa.pub >> authorized_keys Copy the code
This command appends id_rsa.pub to authorized_keys. If authorized_keys does not exist, append it first.
After the append is complete, delete the id_rsa.pub file from the remote copy.
$ rm id_rsa.pub Copy the code
Dengzemiaodemacbook-pro :.ssh dengzemiao$SSH [email protected] iPhone:~ root#Copy the code
This can also achieve a secret free login, pass the public key to the server, achieve the same effect as the previous article, but the important point is to know how to remote transfer copy files to the server.
-
But sometimes after this configuration, you still need to enter a password every time you log in. Why? ~/.ssh/authorized_keys and the authorized_keys folder.
$ chmod 755 ~ $ chmod 755 ~/.ssh $ chmod 644 ~/.ssh/authorized_keys Copy the code
The above command is to grant permissions to a specified folder or file, such as 755, 644, etc. These numbers represent a range of permissions. You can do some research on the chmod command, which will be covered in a future article.
Note: current copy transfer methods are Wifi network transfer, the next chapter will cover USB connection and file transfer, network transfer is certainly not USB connection fast transfer.