1. Generate SSH key
Generate an SSH key on the local computer or source server.
Open the terminal or command line interface and run the following command:
ssh-keygen
According to the prompt, set the path and password of the key to save, and press Enter all the way to indicate that there is no need for a password.
By default, the key is saved in the ~/.ssh/id_rsa file.
2. Copy the public key to the remote server
Use the following command to copy the public key generated on the local computer or source server to the destination server:
ssh-copy-id user@target_server
Where, user is the user name on the target server, and target_server is the IP address or domain name of the target server. After executing this command, you will be prompted to enter the password of the target server.
After entering the password, the system will automatically copy the public key on the local computer or source server to the ~/.ssh/authorized_keys file on the target server.
If you cannot use the ssh-copy-id command, you can also manually copy the public key to the target server.
You can view the public key on your local computer or source server using the following command:
cat ~/.ssh/id_rsa.pub
Copy the public key string in the output result, log in to the target server, and add the public key to the ~/.ssh/authorized_keys file on the target server using the following command:
echo "Public key string" >> ~/.ssh/authorized_keys
Note that when adding the public key to the authorized_keys file, you need to make sure that the file exists. If the file does not exist, create the file first.
Through the above steps, you can copy the SSH public key from your local computer or source server to a remote server for password-free login.
3. SCP file transfer
scp /path/to/file user@target_server:/path/to/destination
Where /path/to/file is the file path to be transferred, user is the user name on the target server, target_server is the IP address or domain name of the target server, and /path/to/destination is the path to transfer files to the target server.
Example:
scp /path/to/file [email protected]:/path/to/destination
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.