This is a solution if you feel that the SCP is cumbersome to enter the password every time.
Suppose you normally develop on Windows, username is Xiang, you have an Ubuntu server wdksw.com, username is root. Now you are ready to upload some files to the server.
For the convenience of narration, w means windows, u means ubuntu.w$ represents the command entered on the Windows side, u$ represents the command entered on the Ubuntu side.
- First generate a pair of keys on the W end
W$SSH-KEYGEN-T RSA
If you press ENTER all the time, the Id_rsa and id_rsa.pub two files are generated under the C:\Users\xiang\.ssh folder.
- Second, ensure that the U-side SSH configuration allows the root user to log on
U$vim/etc/ssh/sshd_config
Make sure Permitrootlogin is yes. My server defaults to Yes. So no changes are required.
- Upload the id_rsa.pub of the win to the server's ~/keys folder
U$mkdir ~/keys
Upload file:
W$SCP ~/.ssh/id_rsa.pub [Email Protected]:~/keys
- Add the uploaded key to the authorization list for SSH
If the. SSH folder does not exist, create it.
U$mkdir ~/.ssh
U$cat ~/keys/id_rsa.pub>>~/.ssh/authorized_keys
The win then tries to use the SCP command and you will find that you do not need to enter a password.
Next, you can write a Python script on the win side to implement a simple file push function.
For example, you want to implement the function of a synchronization disk, automatically synchronize the changed files
No password is required to implement file transfer through SCP command +key