简体   繁体   中英

Is there a way to include the input in the bash file so that I will not type the input required in the command line every time I run the bash script

I am utilizing bash scripts to perform auto deployment on live site with Ubuntu server.

One of the line has something like:

scp build.zip user_name@ip_address:/path/to/releases/$release

Once the Ubuntu execute this command, it will ask me for password input in the command line like:

Enter passphrase for key '/home/user_name/.ssh/id_rsa':

Is there a way to include the input in the bash file so that I will not type the password in the command line every time I run the bash script?

You could use another file in which you write the needed input lines.

./your_script.sh < your_input_file.txt

But that really don't seem like the best idea, I'd rather try to prevent the need for input in each of the sub-commands.

You can permanently remove the passphrase on your id_rsa key by running this command and setting a new blank passphrase:

ssh-keygen -p

For a generic solution, you can use an expect script to programmatically drive and interact with a terminal session.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM