No password is required to implement file transfer through SCP command +key

Source: Internet
Author: User
Tags scp command

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

  • Get

The win then tries to use the SCP command and you will find that you do not need to enter a password.

  • Extended

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.