Mint

How to Pass a Password to the SCP Command in Shell Script in Linux Mint 21

“SCP stands for secure copy and is a Linux command used for copying the desired files and directories securely from one location to another. However, at times while using this command, the users face authentication issues. The target location, i.e., the location that is supposed to receive the file, might have password authentication enabled, and to access that location, you need to provide that password. Therefore, this guide will show you how to pass a password to the SCP command in a shell script in Linux Mint 21.”

Method of Passing a Password to the SCP Command in Shell Script in Linux Mint 21

For passing a password to the SCP command within a shell script in Linux Mint 21, you have to proceed as follows:

Step # 1: Downloading the SSHPass Tool on Linux Mint 21

First, you should download the SSHPass tool on your system by running the following command:

$ sudo apt-get install sshpass –y

Step # 2: Passing a Password to the SCP Command in Linux Mint 21

Now, after installing the SSHPass tool on your system, you need to incorporate the line shown below in your specific shell script. You can even execute this command directly within the Linux Mint 21 terminal:

$ sshpass –p “abcd1234” scp file.txt [email protected]:/home/system/dir/

Here, “abcd1234” represents the password that we have passed, i.e., the password of the recipient location, “file.txt” is the name of the file that we wish to share, and it is followed by the name and IP address of the remote machine from where we want to share this file and also the path of the local machine where we want to copy this file.

Conclusion

Using the method prescribed in this guide, you can conveniently pass a password to the SCP command directly through the terminal or via a shell script in Linux Mint 21. This way, you can bypass all the potential authentication failures while using this command.

Similar Posts