47

I can't see to wrap my head creating an ssh key for GitHub. I had it working quite awhile back but I can't figure out what has changed. I've since removed the previous SSH keys from my GitHub account. After following the instructions several times for generating an SSH key (http://help.github.com/mac-key-setup) and testing "ssh git@github.com" I get the following;

PTY allocation request failed on channel 0 ERROR: Hi...successfully authenticated...GitHub does not provide shell access...Connection to github.com closed.

I reviewed the troubleshooting guide and noticed that my ssh directory didn't have a config file. After creating it I'm unsure of what or how to enter the local path on the IdentityFile line. I'm not even sure whether this is necessary in my case?

If your github authentication information is different from your machine account information, you’ll need to modify your ssh configuration file.

Create or open the file at ~/.ssh/config Add the following lines:

Host github.com
    User git
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile [local path to private key half of github public key you provided]

You may also need to update the permissions on your .ssh folder and its contents. The SSH application will ignore secret files that are too permissive.

$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/*

I also ran ssh -v git@github.com the results of which can be seen here http://gist.github.com/607283 nothing different from what I can tell.

Any idea what I'm doing wrong?

6
  • 27
    The “PTY allocation request failed” warning is innocuous when using command-line ssh to login to a service that does not provide normal interactive access. Git-over-SSH does not need a tty and GitHub’s SSH service is configured to refuse to allocate one for incoming connections. You can tell ssh not to ask for a tty with ssh -T git@github.com. As the next message says, your authentication is working fine. Are you having any problems actually using Git to access GitHub over SSH? Oct 2, 2010 at 6:06
  • Thanks Chris - best explanation I've heard yet. I understand the first part of your comment. I guess the related problem is that when I try to create a new repository and "git push origin master" I return the following "Error: Permission to myemail@address.com/myapp denied to myusername. Fatal: the remote end hung up unexpectedly" So I'm not sure where in the process I'm failing...I thought it was my ssh key. Should I continue to try the ssh -T git@github.com as you suggested?
    – Shawn
    Oct 2, 2010 at 15:12
  • We see the “successfully authenticated” message, so there is no need to continue to try to directly ssh into GitHub. I mentioned the -T option to demonstrate that the “PTY allocation” message does not indicate a hard failure (you get the same “successfully authenticated” message whether you run with -T or not). I will write more about the real problem in an answer. Oct 2, 2010 at 19:25
  • Also, when replying to comments, if you begin your comment with “@username” ( details on MSO ), then the indicated person will be more likely to notice your comment. I would have missed your comment if I had not come back to check on this question. Oct 2, 2010 at 19:37
  • 4
    Difference for me was ssh -t vs ssh -T Aug 25, 2014 at 18:15

1 Answer 1

40

As described in the comments on the question, 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).


The person who asked the question wrote this in a comment:

I guess the related problem is that when I try to create a new repository and "git push origin master" I return the following "Error: Permission to myemail@address.com/myapp denied to myusername. Fatal: the remote end hung up unexpectedly"

This seems more likely to be the actual problem. This seems to indicate that the remote named origin not configured to correctly point to a GitHub repository.

Check the output of git remote show -n origin. Probably the “Fetch URL” and the “Push URL” are the same. They should both look like this:

git@github.com:git-user-name/repository-name

When logging into GitHub on the web you can use either your account’s username or its associated email address. When pushing to repositories (or fetching from private repositories) you have to use your actual username (an email address will not work). It looks you are using your email address in there instead of just your GitHub username. To fix this, reconfigure the remote’s URL:

git remote set-url origin git@github.com:github-username/repository-name

Your username is displayed in many places on the GitHub web pages once you are logged in. The easiest place to find it is between your gravatar and the “Dashboard” link on the page header (you will see a silhouette icon if you do not have a gravatar configured). That same location links to your public profile page; this page’s URL should also end in your username.

4
  • @chris-johnsen When I'm in the correct directory, I entered "git remote set-url origin..." as instructed but the return is "error: Unknown subcommand: set-url" and provides alternative commands for git remote, none of which seem to relate. Is it possible that instead I need to use "git config --global user.name myusername and git config --global user.email myemail@mail.com"?
    – Shawn
    Oct 2, 2010 at 22:17
  • @Shawn: Ah, git remote set-url is only in Git 1.7.0 and higher. Just do git config remote.origin.url 'git@github.com:github-username/repository-name' or edit the config with git config -e (1.6.3 and higher; or just vim .git/config ☺). The user.name and user.email values are only used when making commits, not when pushing. Oct 3, 2010 at 8:36
  • @chris-johnsen Thanks for all of your help and patience. The background you provided helped clarify the question I wasn't able to communicate. Here's what I realized and sorted out...1.) deleted the original repository, 2.) Upgraded to the latest version of Git, 3.) In parallel with your comments, the RailsTutorial.org guide, Pro Git and GitHub Repository creation instructions I realized I had been entering the wrong user name when I did git config --global user.name "my username" and 4.) Finally able to push to GitHub! Thanks again for your help!
    – Shawn
    Oct 3, 2010 at 18:33
  • I wish I could vote this up twice. I started github knowing how ssh works, and succeeded with "ssh -T git@github.com". Then took their advice on how to configure my remote "git remote add origin github.com/username/repo.git" and of course that is the https syntax, not ssh. Github should note this, or I should stop typing on autopilot, or both. Jun 20, 2012 at 3:23

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.