I spent a lot of time last week getting Git to work over ssh.
(Git is a software version control tool. It’s a software developer thing. Feel free not to read this if you don’t care about Git or software. I’m putting this up for the next poor yuck who’s got this problem and is praying to the Google gods for an answer.)
Here’s the problem.
I’m working on a web project. The web hosting service gives us access to the project on Git over an ssh (secure) connection.
The hosting company created and installed the ssh keys and gave us a copy of the private key. Then they disappeared. (Not really. They’re still there. But they live in India where there was a big holiday this week, so they weren’t answering email.)
I put my private key in the ~/.ssh directory. I fire up a terminal window. I type:
git pull ssh://email@example.com/projectname.git
The server asks for a password.
I don’t have a password. All I have is this key file. And they’re off the hook in India.
Here’s what you have to do.
In your ~/.ssh directory, look for a file called
config. If you don’t have one, fire up your text editor and make a new one.
Along with whatever may already be there, add:
Host git.hostingservice.com Hostname git.hostingservice.com User git IdentityFile ~/.ssh/privateKeyFile
Technically, you can call the host (on the first line) anything you want. Call it george if you want. I’ve made it the same as the hostname because I use SublimeText with SublimeGit as my IDE, and SublimeGit always calls the Git Host by the Hostname. But if you’re just using the command line, anything goes.
One last thing. You have to check the permissions on the key file. When I first just dropped it into the ~/.ssh directory, it inherited the 0644 permissions of everything else. Ssh hates that. It will ignore keys that are open to the public. Set the key file’s permissions to 0600.
Now you’re good to go. From the command line, you can call Git and ssh into whatever you called the host:
git pull ssh://george/projectname.git
And you’re off and running.
At least, that’s what worked for me.