Installation and use of sshpass
Introduction: sshpass can solve the problem of interactive password input in scp. Mainly used in scripts, the disadvantage is that it is easy to expose passwords and disclose security information.
1. Installation
Yum install sshpass
2. Use the command
Sshpass-p (passwd) scp (absolute path file) root@ (IP): / data
# if you need to add a scp-r parameter to copy a folder
3. Script mode
#! / bin/bash password=qwer user=root ip=192.168.1.100 file=/home/file.txt sshpass-p $password scp file $user@$ip:/data/
Script optimization:
1. Password, user and ip can be set as variables for input reading.
2. Multiple different IP can be set to ip_list.txt, and then loop with for
3. Files can also be in the form of for loop
4. You can add judgment, such as copying different files to different ip nodes.