In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use sshpass in linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
In most cases, when a Linux system administrator logs in to a remote Linux server using SSH, he or she logs in with either a password or a passwordless SSH login or key-based SSH authentication.
What if you want to automatically provide the password and user name in the SSH login prompt? That's when sshpass can help you.
Sshpass is a simple, lightweight command-line tool that enables us to provide passwords (non-interactive password authentication) to the command prompt itself, so that backups can be made through cron scheduler executing automated shell scripts.
Ssh uses TTY access directly to ensure that the password is entered by the user's keyboard. Sshpass runs ssh in a dedicated tty to mislead ssh into believing that it is a password received from the user.
Important: using sshpass is the least secure because users on all systems can see the password from the command line with a simple "ps" command. Therefore, if necessary, such as in a production environment, I strongly recommend using SSH password-less authentication.
Install sshpass in Linux
On RedHat/CentOS-based systems, you first need to enable the EPEL repository and install it using the yum command.
# yum install sshpass # dnf install sshpass [Fedora 22 and above]
In Debian/Ubuntu and its derivatives, you can use the apt-get command to install.
$sudo apt-get install sshpass
In addition, you can also install sshpass from the source code of * *. First download the source code and extract the content from the tar file:
$wget http://sourceforge.net/projects/sshpass/files/latest/download-O sshpass.tar.gz $tar-xvf sshpass.tar.gz $cd sshpass-1.06 $. / configure # sudo make install
How to use sshpass in Linux
Sshpass is used with ssh. Use the following command to see a complete description of the usage options for sshpass:
$sshpass-h
The following is the sshpass help content displayed:
Usage: sshpass [- f |-d |-p |-e] [- hV] command parameters-f filename Take password to use from file-d number Use number as file descriptor for getting password-p password Provide password as argument (security unwise)-e Password is passed as env-var "SSHPASS" With no parameters-password will be taken from stdin-h Show help (this screen)-V Print version information At most one of-f,-d,-p or-e should be used
As I mentioned earlier, sshpass is more reliable and useful for scripting, as shown in the example command below.
Log in to the remote Linux ssh server (10.42.0.1) with a username and password and check the file system disk usage, as shown in the figure.
$sshpass-p 'my_pass_here' ssh aaronkilik@10.42.0.1' df-h'
Important: here, a password is provided on the command line, which is not secure and this option is not recommended.
Sshpass-remote login to Linux using SSH
However, to prevent the password from being displayed on the screen, you can use the-e flag and enter the password as the value of the SSHPASS environment variable, as follows:
$export SSHPASS='my_pass_here' $echo $SSHPASS $sshpass-e ssh aaronkilik@10.42.0.1'df-h'
Sshpass-hide the password in the terminal
Note: in the above example, the SSHPASS environment variable is used for temporary purposes only and will be deleted after reboot.
To set the SSHPASS environment variable, open the / etc/profile file and enter the export statement at the beginning of the file:
Export SSHPASS='my_pass_here'
Save the file and exit, and then run the following command to make the changes take effect:
$source / etc/profile
Alternatively, you can use the-f flag and put the password in a file. In this way, you can read the password from the file, as follows:
$sshpass-f password_filename ssh aaronkilik@10.42.0.1'df-h'
Sshpass-provide a password file when logging in
You can also use sshpass to transfer files over scp or rsync to back up / synchronize files, as follows:
-Transfer Files Using SCP-$scp-r / var/www/html/example.com-- rsh= "sshpass-p 'my_pass_here' ssh-l aaronkilik" 10.42.0.1:/var/www/html-Backup or Sync Files Using Rsync-$rsync-- rsh= "sshpass-p 'my_pass_here' ssh-l aaronkilik" 10.42.0.1:/data/backup/ / backup/
For more usage, it is recommended to read the man page of sshpass and enter:
$man sshpass Thank you for your reading! This is the end of this article on "how to use sshpass in linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.