For "some purpose" I have added a script in the ~/.bashrc to prompt for a secondary password and its serves my purpose. But, there is only one small issue is there.

When I scp to the server, It fails due to my custom script in the ~/.bashrc The error I am getting when doing a scp is "stdin: is not a tty"

I invoke sh second_pass.sh from the ~/.bashrc

Content of second_pass.sh:

trapeze ()  {
    printf "Trying to kill me!!" }

trap trapeze SIGINT

while true; do echo "Please enter the password:" read -s password

if [[ -z "$password" ]] ; then
    continue ; fi

hash="$(echo -n "$password" | md5sum )" password=`echo "$hash" | awk '{print $1}'`

if [ "$password" == "a359c98e8c05feaf91bdb8cfc7dd6b" ] then
    exit ; else
    echo "WRONG!!!" fi done

the result is, when I do scp is

stdin: is not a tty
Please enter the password:

and then scp fails.

I want to use the scp & also keep the password prompting script in my ~/.bashrc.
How can I achieve it ?

  • 1
    I think you can't - the scp protocol wants standard input/output for itself, so even if you allocated a TTY (-o RequestTTY=force) it would fail later, and if it were using SFTP inside you probably wouldn't have the error now. See e.g. this question for a similar failure. Note though that what you're doing doesn't actually provide any security whatsoever, so if you're expecting that to be real then consider another approach. – Michael Homer Jan 17 '15 at 9:34
  • 1
    Note that your password is now know for anyone reading this page. – user367890 Jan 17 '15 at 9:48
  • how any one know my password ? It is in MD5 and more over, I deleted some char from that. – Mani Jan 18 '15 at 12:48
  • @Mani: Brute force, rainbow tables, online services, crack farms. Your edit is visible for anyone clicking the edited link below your post. One can ask mods to remove such history in special cases, but it would be of little help. It has long since been cached and copied to various servers around the world. Look for example here: unixlinuxcm.blogspot.com/2015/01/… – user367890 Jan 18 '15 at 20:52
  • After a quick search. You could for example try your hash here: md5online.org – user367890 Jan 18 '15 at 20:54

try replacing

 while true ; do echo ...


 while tty -s ; do echo ...

This will disable double password checking.

This might not be you intend.

Now if you keep to your double password strategy, the only choice left is to pull the file with scp once your are loggon (and twice identified), this depend on the plateform the file is comming from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.