Get the App
SLTechnology News&Howtos  ›  Servers  › 

Installation and use of sshpass

Shulou Source: shulou.com Published: 2022-06-03 09:46:36 12月06日 Update

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.

Tags: Files different ways scripts passwords copies loops input security interaction information parameters variables commands multiple folders shortcomings nodes paths Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology Huawei Shulou Information macOS