Reputation: 2140
This is the first time it has happened to me where I am using the su command and it actually displays the password on the terminal and doesn't stay hidden. Here is my code snippet:
sshpass -p "password" ssh -q [email protected] "su -lc 'mkdir temp/'"
Code explanation: I am accessing a remote server and trying be root on that server to create a folder. In doing so I have to use the su command and it prompts me for the password. When I enter the password, it gets displayed and doesn't stay hidden. How do I fix that?
Upvotes: 0
Views: 1034
Reputation: 923
Just like I replied to you here.
It's possible to keep it "hidden" from the command line:
Edit your /etc/profile
and paste there:
export SSHPASS='my_pass_here'
Use the -e
argument with sshpass
command
$ sshpass -e ssh [email protected] 'ls -ll'
Another option is to save your password in a different file and use the -f
argument:
$ sshpass -f password_filename ssh [email protected] 'ls -la'
But the best solution is to follow the @Hristo Mohamed suggestion:
In general please AVOID using sshpass with a password.
You can set up easily a generate ssh key just to do this job and then remove it.
Upvotes: 0
Reputation: 58324
The solution is to allocate a pseudo TTY (using the -t
option on ssh
):
sshpass -p "password" ssh -t -q [email protected] "su -lc 'mkdir temp/'"
Without this, there's no "terminal" in this context and su
is unable to disable echo of the password.
Upvotes: 1