Home >Operation and Maintenance >Linux Operation and Maintenance >How to pass password to ssh/scp command in bash script
sshspass is a very useful tool for running ssh authentication in non-interactive mode. Using sshspass, you can use passwords for ssh or scp commands without interaction, which helps when using passwords in shell scripts. We recommend using key-based authentication instead.
Install SSHPASS
For most recent operating systems, the sshpass package is available in the default package repository. It can be installed on your system using the following command.
On Debian:
$ sudo apt install sshpass
On CentOS:
$ yum --enablerepo = epel -y install sshpass
Using SSHPASS
sshspass Use the sshspass environment variable to store user passwords . Need to use sshspass variable and password first and then use this command. Below is a simple shell script using sshspass.
export SSHPASS=ry3AvbWO0oupYX9HCMzp0Axx sshpass -e scp testfile.csv user@example.com:/uploads/
You can also use sshpass to run the ssh command, as shown below
sshpass -e ssh user@example.com
This article has ended here. For more exciting content, you can pay attention to other related columns of the php Chinese website Tutorial! ! !
The above is the detailed content of How to pass password to ssh/scp command in bash script. For more information, please follow other related articles on the PHP Chinese website!