How to give password in shell script?
If you can't use ssh trust and must enter the password later on in your script, use read -s -p "Password:" USER_PASSWORD
to silently read in the password. You can then export USER_PASSWORD
to an expect script, avoiding it being displayed in ps
:
#!/usr/bin/expect -f spawn scp some.file USER@otherhost:~ expect "assword:" send -- "$env(USER_PASSWORD)\r" expect eof
I think it's a better idea to generate an authentication key, and use this key based authentication instead of writing plain text passwords into your scripts.