SHELL-SCP automatically enter the password

Source: Internet
Author: User
Tags scp command

On Linux, we can easily use the SCP command to copy files remotely, but because the SCP command itself has no save password option, so in the shell can not be like samba that way to save the password, more trouble, the following two implementation methods are described below.

Method One:

SSH Public key authentication


Method Two:

Expect (expect-programmed dialogue with interactive programs, Version 5) implementation

Default installation requires manual installation of the expect package: Yum-y Install expect Expect-devel

#! /bin/bash
Expect-c "
Set timeout 1200; # #设置拷贝的时间, depending on the size of the directory, I'm here for 1200 seconds.
Spawn/usr/bin/scp-r 192.168.0.201:/work/backup/db_back//work/dbback/
Expect {
\ "*yes/no*\" {send \ "yes\r\"; Exp_continue}
\ "*password*\" {send \ "123456\r\";} # #远程IP的密码.
}
Expect EOF; "

If you do not set timeout, you will automatically exit, so you must set or use the default field to set the expect timeout or exit action.


This article is from the "Wine" blog, please be sure to keep this source http://knowledge92.blog.51cto.com/7143076/1677865

SHELL-SCP automatically enter the password

Related Article

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.