47

Ok, I'm confused about something... I am able to commit to my github repository just fine, but when I try to do a cap deploy from my local folder to my staging server I get Permission denied (publickey).

If I run ssh git@github.com I actually get an error PTY allocation request failed on channel 0

So something here is wrong.

If I run ssh -vT git@github.com I get:

OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/myuser/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: Connection established.
debug1: identity file /Users/myuser/.ssh/id_rsa type 1
debug1: identity file /Users/myuser/.ssh/id_rsa-cert type -1
debug1: identity file /Users/myuser/.ssh/id_dsa type -1
debug1: identity file /Users/myuser/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2
debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/myuser/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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: /Users/myuser/.ssh/github_rsa
debug1: Remote: Forced command: gerve technomad
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: Remote: Forced command: gerve technomad
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
debug1: Remote: Agent forwarding disabled.
debug1: Remote: Pty allocation disabled.
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([207.97.227.239]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply 0
Hi technomad! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2384, received 2888 bytes, in 0.1 seconds
Bytes per second: sent 42630.8, received 51643.3
debug1: Exit status 1

My keys are in the ~/.ssh folder, so whats the issue, and why am i able to commit to the repository if there is a key issue??

UPDATE: I did notice something when I went into my .ssh folder. There is a new keypair that was created when I installed Github for Mac... why couldn't it just use my existing keypair i don't know.

GiH
  • 14,006
  • 13
  • 43
  • 56

6 Answers6

130

I had to do the following:

   $ ssh-add -D   #remove existing identities
   $ ssh-agent    #copy the lines & run them
   $ ssh-add      #uses the output from above
olore
  • 4,687
  • 3
  • 28
  • 40
  • 2
    This is exact answer to the problem. No need to add ssh key on your stage machine. Just run above command and done... Thanks @olore – Rahul Chaudhari Jul 14 '14 at 07:15
  • 15
    But what is reason behind this, and what this command did to solve this? – Rahul Chaudhari Jul 14 '14 at 07:32
  • 8
    The above command adds the RSA/DSA identities to the authentication agent, which checks permission when you deploy. For some reason if the identities are not added before you run the deploy command, you will get the permission denied error. For me, whenever I restart my computer, I needed to type the above commands to make it work. I figured that my ssh public key was not getting added automatically after each restart. So, I used `ssh-add -K` after the above commands to add the output to Keychain. After that my issue was solved permanently. – Brian Russel Davis May 25 '16 at 20:53
  • I had a huge problem with it in Debian with a key with a different name than `id_rsa`. I just did `ssh-add $HOME/.ssh/[key_name]`. –  Jul 25 '17 at 06:48
  • This worked for me. I was getting the error after transferring my filesystem to a new computer. – Daniel Ristic Aug 14 '17 at 12:47
  • note: I also need to add another public key (not only my id_rsa) , so, `ssh-add -K ~/.ssh/my_public_key.pem` – Patricio Jofre Nov 23 '19 at 13:22
  • I recently updated my github access key and ran into this issue. This answer solved the problem in a minute for a legacy project using rails/4 and capistrano/2. Thanks! – dgg Jun 12 '23 at 19:17
42

I get this error sometimes and I just type $ ssh-add -k to add my identity and then it works. Not sure exactly why this works or why the error message doesn't suggest it, but it always comes in to the rescue!

Catfish
  • 18,876
  • 54
  • 209
  • 353
19

I would make sure your staging server has ssh access to github. Run the same command "ssh -vT git@github.com" via a terminal on your staging server; this will help determine if it is ssh problem on the remote machine.

Dave Bettin
  • 2,322
  • 1
  • 18
  • 9
  • That worked thanks :), I was overlooking that part. But I still don't know why "ssh git@github.com" is returning "PTY allocation request failed on channel 0"? – GiH Nov 01 '11 at 20:16
  • Can you ssh to other servers without that problem surfacing? – Dave Bettin Nov 01 '11 at 20:35
  • yup, when I ssh into my server it works fine, its only "ssh git@github.com", actually if I do "ssh -T git@github.com" it works fine too... so why doesn't it work without the -T option? Could it be an issue with Mac OSX lion? – GiH Nov 02 '11 at 03:09
  • 1
    I would check out this thread: http://comments.gmane.org/gmane.os.cygwin/125243. HTH. – Dave Bettin Nov 02 '11 at 15:03
  • 1
    Thanks, you're link eventually led me to this answer http://stackoverflow.com/questions/3844393/what-to-do-about-pty-allocation-request-failed-on-channel-0. To quote the answer "the 'PTY allocation request failed' is a red herring with respect to GitHub authentication (it is the result of trying to interactively login to GitHub when the only SSH service they offer is non-interactive Git-over-SSH; the authentication is working, they just do not provide interactive, “shell” service)." – GiH Nov 02 '11 at 15:43
  • GitHub doesn't provide shell access, hence the PTY allocation error. That's supposed to happen. – Elle Mundy May 27 '14 at 18:06
  • 1
    Just a quick note that this can be a red herring if you have `set :ssh_options, forward_agent: true` (which is a good way to deal with keys in capistrano). If you're using agent forwarding, you won't necessarily be able to ssh to github from the remote server even if everything else is working, which means the original problem is likely related to local ssh config. – Dane Jul 07 '14 at 16:29
3

If you are using MAC. Maybe your ssh key is not added to authentication agent. Following command will do that

ssh-add path_to_private_key

for example

ssh-add ~/.ssh/id_rsa
Rajat Bansal
  • 885
  • 9
  • 7
3

I met with the same problem after installing GitHub for Mac OS X. The application created a new ssh private key in ~/.ssh/github_rsa and added it to the ssh authentication agent.

Check which key the ssh auth agent has cached:

$ ssh-add -l
2048 63:0c:a6:51:63:c1:35:76:5d:02:77:97:39:48:0e:4a /Users/jiangxin/.ssh/github_rsa (RSA)

Whenever you connect to github.com or another ssh services, this key is used first.

Clear the cached keys from ssh-agent using this command:

$ ssh-add -D

Now the ssh client should work normally, using the key defined in ~/.ssh/config or ~/.ssh/id_rsa.

Nick Urban
  • 3,568
  • 2
  • 22
  • 36
Jiang Xin
  • 51
  • 2
0

The error is because, ssh-add does not know how to talk with the authentication agent. The problem can be solved by setting SSH_AUTH_SOCK environment variable.

If you run ssh-agent you should get some output like this:

SSH_AUTH_SOCK=/tmp/ssh-agVZL13989/agent.13989; export SSH_AUTH_SOCK;
SSH_AGENT_PID=13990; export SSH_AGENT_PID;
echo Agent pid 13990;SSH_AUTH_SOCK=/tmp/ssh-agVZL13989/agent.13989; export SSH_AUTH_SOCK;
SSH_AGENT_PID=13990; export SSH_AGENT_PID;
echo Agent pid 13990;

Execute this :

eval $(ssh-agent)

And then :

ssh-add -D
Sankalp Singha
  • 4,461
  • 5
  • 39
  • 58