Shell password input does not display, the shell output content does not display the password, the shell implements has the password automatic login Sshpass application Practice

Source: Internet
Author: User






In many practical projects, we often through SSH authentication, such as copy files via SSH, although we can use the public key and private key to implement SSH password-free login, on different servers need to pair the corresponding key, switch user trouble and other issues, in some need to interact but will involve batch processing, Shell password input does not display, the shells output content does not display the password, the shell implementation has the password automatic login will greatly increase the efficiency

#! / bin / bash
#############################################
#Author: liaodengsong
#date: 2015-12-10
#Emil: [email protected]
#Cropright: [email protected]
# version = "0.5"
#############################################
shellDir = $ (cd "$ (dirname" $ 0 ")"; pwd)
prog = "ysa-release"
platform = "YNedut"

releaseDir = "[email protected]: / home / ysa-web"
cmdRsync = "rsync -avzrt --delete --progress -e‘ ssh -p 59422 ’"

fileHome = "/ home / ysa / target / EveryVersionFile"
verHome = "/ home / ysa / target / version"

echo "please input the version key:"
read verKey
echo "please input the verDataBases key:"
read dbKey

if [! -d $ {fileHome} / $ {verKey} /] || [! -f $ {verHome} / $ {dbKey}]; then
        echo "The Key Error, exit!"
        exit 0;
fi

echo "please input the release host user password:"
stty -echo
read PASSWORD
stty echo

fDir = "$ {releaseDir} / files /"
vDir = "$ {releaseDir} / version /"

echo "sshpass -p $ PASSWORD $ cmdRsync $ {fileHome} / $ {verKey} / * $ fDir"> / dev / shm / tempCMD
echo "sshpass -p $ PASSWORD $ cmdRsync $ {verHome} / $ {dbKey} $ vDir" >> / dev / shm / tempCMD
awk ‘{$ 3 =" *** "} 1’ FS = ‘‘ OFS = ‘‘ / dev / shm / tempCMD
echo "Any key to continue!"
read -n1
source / dev / shm / tempCMD
rm -f / dev / shm / tempCMD


One, do not display the password entered by SSH

stty -echo
read PASSWORD
stty echo #Close input does not display
Reference website: http://www.jb51.net/article/40654.htm



Second, the password entered through SSH is used to automatically log in

sshpass -p $ PASSWORD ssh [email protected] #Realize SSH automatic login in shell script
Reference website: http://blog.csdn.net/gsnumen/article/details/7293274

CentOS6 install sshpass:

cd /etc/yum.repos.d/
wget http://download.opensuse.org/repositories/home:Strahlex/CentOS_CentOS-6/home:Strahlex.repo
yum install sshpass


Third, the password information is not displayed when the information is output

awk ‘{$ 3 =" *** "} 1’ FS = ‘‘ OFS = ‘‘ / dev / shm / tempCMD #When the SSH password entered in the third column is displayed on the screen, it is displayed as *
Reference content: http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=3751275

http://bbs.chinaunix.net/thread-2309494-1-1.html

Key content excerpts to be verified:

cat filename | while read line
do
echo "$ line" | awk -F \ | -v v = \ | ‘{print $ 1v $ 2v $ 3v $ 4v" "v $ 6v}’
done
awk ‘BEGIN {OFS = FS =" | "} {$ 5 =" ";} 1‘ file
awk ‘{$ 5 =" "} 1‘ FS = \ | OFS = \ | infile


This article is from the "Linux_Operation_Automation" blog, please keep this source http://artman.blog.51cto.com/3218204/1721608

Shell password input does not display, Shell output does not display password, Shell implements password automatic login sshpass application practice

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.