0

I have a SSH Key that uses no passphrase. I want to use that key to pull a private git repository when building a Docker container.

I successfully managed to get the key into the container at build time but now SSH fails because it can't open /dev/tty to ask for the key's passphrase. The key doesn't have one, as mentioned.

Here's some of the SSH output (-v)

debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_load_private_type: incorrect passphrase supplied to decrypt private key
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug1: No more authentication methods to try.
Permission denied (publickey).
fatal: Could not read from remote repository.
Lerk
  • 946
  • 1
  • 15
  • 21
  • Note that I already tried adding `/dev/tty` by using the method suggested [in this thread](http://stackoverflow.com/a/18079668/1979736) – Lerk Apr 11 '17 at 14:24

1 Answers1

2

Your key file might be corrupt in some way. ssh (at least some versions) will prompt for a passphrase any time it can't make sense of the key file:

$ dd if=/dev/urandom of=key bs=1500 count=1
1+0 records in
1+0 records out
1500 bytes transferred in 0.000190 secs (7893922 bytes/sec)
$ chmod 600 key
$ ssh -i key foo@localhost
Enter passphrase for key 'key':
Kenster
  • 23,465
  • 21
  • 80
  • 106
  • That's most likely the problem. Thanks for the hint. :) – Lerk Apr 11 '17 at 15:04
  • This was indeed the problem. The newlines in the keyfile were missing. I fixed it by using another way to get the key into the image. – Lerk Apr 11 '17 at 15:20
  • I don't remember it exactly but I had to do the clone when running the image instead of when building it. – Lerk Apr 13 '18 at 11:28
  • 1
    This was my case also: key file was corrupted due to the textEdit on mac os x. I should remember not to use this as an editor in the future...Anyways..opened file with Sublime Text, emptied it, copy paste the key again and it worked like a charm . Thanks! – Crenguta S May 02 '18 at 09:29
  • We had this problem due to DOS line endings (CR-LF) in the key file, when used on a Linux machine. After changing line endings to Unix/Linux convention (LF only) it worked. (I would have expected SSH to be more tolerant, especially in a file format that is designed to be copy-and-pasted, mailed etc.) – starblue Jul 04 '22 at 11:11