2


I have created a shell script as given below.And I need to hide the password, which i will be given when the script prompt for that. If I run the below script written inside the single quotes in my local machine, it will hide the password. But if I add the SSH part it wont.

What should I do for hiding password ?

ssh [email protected] 'echo -n Password:; read -s password; echo; echo $password; ' 

3 Answers 3

5

Try using the -t option to ssh to force tty allocation.

ssh -t [email protected] 'echo -n Password:; read -s password; echo; echo $password;' 

EDIT: explanation of suggested solution

If not running a login-session but just a command instead by default SSH won't allocate a pseudo terminal device for the running process. This behavior is not a bug a all, but delibarately chosen by design.

This way it is possible to pass binary data uninterpreted between different machines. Maybe something like:

ssh whoever@wherever 'cat remote_file' | local_program 

Passing data between two machines this way would almost be impossible if the data was filtered by a terminal driver in between - Think of the tons of escape sequences you would have to care about !

Without any terminal allocated there is no way of hiding user input. Any attempts to stty something will fail, as there isn't any terminal at all!

To make ssh allocate a pseudo terminal even if not running in a login-session you have to pass the -t parameter to force tty allocation.

Sign up to request clarification or add additional context in comments.

1 Comment

Seems like, I got a hang of what is going on, though a bit. But still the input is useful :-)
0

Better use ssh keys, that way, no need to pass a password with the help of a ssh-agent. see a good how-to : https://wiki.archlinux.org/index.php/SSH_Keys

2 Comments

Actually I just need to hide what i have given.Not specifically for password.If there is an option for entering bank account number and if I want to hid it from others, what should i do for hiding it.
@sputnick: sry, that would be me then. I "downvoted" (nice term I just learned) because the answer while definately a good idea to operate ones ssh passwords/keys it still doesn't fit to the problem described: qerying for any kind of password e-mail file-encryption or whatever. To repeat while sure a pretty perfect solution to the ssh key handling problem I tought the answer might be missleading in respect to the given question.
0

I am new to scripts, though I guess this might can help you :

#!/bin/sh echo -n "Enter Password : " stty -echo read password < /dev/tty stty echo echo echo -n "Enter Password again : " stty -echo read password1 < /dev/tty stty echo echo echo "Password Entered are : $password and $password1" 

3 Comments

IMHO this wont work either as in non-interactive mode there won't be any pseudo terminal allocated on the target machine thus stty and the -s option failing to work.
@mikyra : Wish I really could understand one bit of what you talking about. I am too new to LINUX, so you can guess regarding how new I am to scripts :-). I just learned this thingy few days ago, so I thought might be this would work. I am really not sure, just wanted to give one more option to the OP to look at.
based on the feedback given, I updated the post made above with some kind of rationale. Take a look there if you are still curious.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.