Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Pass Password to ssh/scp Command in Bash Script

    How to Pass Password to ssh/scp Command in Bash Script

    By RahulFebruary 12, 20191 Min Read

    sshpass is a useful tool used for running ssh authentication in non-interactive mode. Using sshpass you can use passwords to ssh or scp command without interactions, which helps to utilize in shell scripts. Instead of using this we recommend using key based authentication.

    Advertisement

    Install sshpass

    The sshpass package is available in default packages repositories for most of the latest operating systems. You can use following commands to install it on your system.

    On Debian:

    sudo apt install sshpass
    

    On CentOS:

    yum --enablerepo=epel -y install sshpass
    

    Using sshpass

    sshpass uses SSHPASS environment variable to store user passwords. You need to first SSHPASS variable with password then use this command. Here is a simple shell script using sshpass.

    1
    2
    3
    export SSHPASS=ry3AvbWO0oupYX9HCMzp0Axx
     
    sshpass -e scp testfile.csv user@example.com:/uploads/

    You can also run ssh command as following with sshpass.

    1
    sshpass -e ssh user@example.com

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    How to Install MySQL 8.0 on RHEL & CentOS Stream 9

    How to Split Large Archives in Linux using the Command Line

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.