Redson
Redson

Reputation: 2140

How to get rid off "no access to tty (Bad file descriptor)" message in bash?

I have a bash script where I use ssh to connect to another server and run some commands there. I found some sites that the error (Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.) is a friendly message but my bash script gets "stuck". No other commands are executed after this message appears. Other forums said to use ssh -t to suppress the message but its not working for me. My code looks something like this:

.
.
.
stty -echo
sshpass "pwd" ssh -o StrictHostKeyChecking=no [email protected] 'su -lc "rm -rf tmp"' 2>/dev/null
stty echo
.
.
.

The reason why I'm using stty-echo is because I need to switch users to root and the password is displayed on the terminal (which I don't want). I get the error message (Warning: no access to tty (Bad file descriptor). Thus no job control in this shell.) after I enter the password for root on the connect server (ip: 1.1.1.1).

Any suggestions? Let me know if further explanation is required. Thanks! (My version of bash is GNU bash version 3.2.51(1))

EDIT

The error message I get when removing 2>/dev/null is:

Warning: no access to tty (Bad file descriptor).
Thus no job control in this shell. 
stty: standard input: Invalid argument

Upvotes: 3

Views: 8271

Answers (1)

Amar
Amar

Reputation: 63

Instead of trying to hide the password, I would suggest that you make ssh connections passwordless by adding your ssh public key to the destination id/server. You must have a passphrase for your key and use ssh-agent to provide it when needed.

Upvotes: 1

Related Questions