Linux - Can't SSH As Tty-Less User - Server Fault
Linux - Can't SSH As Tty-Less User - Server Fault
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required. Sign up ×
I am trying to run a single command by invoking ssh (using key authentication) from a user which does not have a tty (the user my
apache server is running as) and keep getting the following result:
The -t flag is set when invoking ssh. The key does not have a passphrase, which should suppress the need for any input, but
apparently it doesn't. How can I prevent ssh from trying to open /dev/tty?
Edit3: I tried ssh-ing using the same key as root and got this result:
It prompts me for a passphrase even though it shouldn't need any. Furthermore, I can use the key to ssh in using PuTTY on a windows
machine just fine and it doesn't prompt me for a passphrase.
Edit4: I added the server to the apache users known_hosts and now I get this:
[localhost]:54367 ecdsa-sha2-nistp256
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBILr7jLp5CeYfyrCroaDjkaWgDHXRrQD
Edit5: Solved. The problem was that the key pair was generated by PuTTY, which writes the private key in a format which isn't
compatible with OpenSSH. Solution provided by cjc in a comment.
linux ssh
Re: code tag. No, either surround code with back-tick, or put 4 spaces in front of the line. – cjc Mar 21 '12 at
23:37
What's the full ssh command? – cjc Mar 21 '12 at 23:38
@Zoredache Thought it would help. Some site suggested it. – Surma Mar 21 '12 at 23:45
1 @Surma, ecdsa is referring to the server's key, not the key on the client. – amcnabb Mar 22 '12 at 0:12
2 Answers
The problem doesn't actually seem to be that it's trying to read the passphrase--that's just a
warning. Rather, it's trying to do host key verification but failing. If you really want it to never
ask about host keys, consider adding the following options to the ssh command line:
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o
GlobalKnownHostsFile=/dev/null
Note that there may be security implications, so make sure to read about these options in the
ssh_config man page.
EDIT: Given your updated error messages, it looks like you have a corrupted identity file (or as
cjc pointed out, it might be in the wrong format). Try creating a new one manually with ssh-
keygen, and add it to the server's authorized_keys.
You seem to be right, I just tried to use the key as root. Result in OP. – Surma Mar 21 '12 at 23:54
1 Actually, instead of using StrictHostKeyChecking=no, you can also get the server's public key and stick it in
the user's .ssh/known_host file. Or put that in the system-wide known_hosts file. – cjc Mar 22 '12 at 0:00
@cjc, I agree that's usually the better solution. – amcnabb Mar 22 '12 at 0:03
@cjc I copied the known_hosts from root (who added the server to the known hosts) and set up the correct
permissions. I get different output now, check the OP. – Surma Mar 22 '12 at 0:06
1 @amcnabb You mentioned that you used the key in PuTTY. Did you convert the key to OpenSSH? – cjc Mar
22 '12 at 0:12
Out of interest, what is set as the environment in /etc/passwd - the lack of /bin/bash will
probably be your issue.
/bin/false I probably should have mentioned that this is being run by php, which apparently spawns a shell
when you invoke shell_exec() (which is what I'm using to run this). – Surma Mar 21 '12 at 23:53
1 Understood. Then in that case, why are you not just using pecl.php.net/package/ssh2 - rather than hacking
through with shell_exec() – Ben Lessani - Sonassi Mar 21 '12 at 23:57
Sure is, you should really explain in your question that you are attempting to do this via PHP - as the answer
I've provided is more accurate to solve your question. – Ben Lessani - Sonassi Mar 22 '12 at 12:30