1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
1. <span class="step-title">Check for SSH keys. <span>Have an existing key pair? You can skip to Step 4.</span></span>
First, we need to check for existing ssh keys on your computer:
<pre class="terminal bootcamp">
<span class="codeline">$ cd ~/.ssh<span>Checks to see if there is a directory named ".ssh" in your user directory</span></span>
</pre>
If it says “No such file or directory“ skip to __step 3__. Otherwise continue to __step 2__.
2. <span class="step-title">Backup and remove existing SSH keys.</span>
Since there is already an SSH directory you’ll want to back the old one up and remove it:
<pre class="terminal bootcamp">
<span class="codeline">$ ls<span>Lists all the subdirectories in the current directory</span></span>
<span class="bash-output">config id_rsa id_rsa.pub known_hosts</span>
<span class="codeline">$ mkdir key_backup<span>makes a subdirectory called "key_backup" in the current directory</span></span>
<span class="codeline">$ cp id_rsa* key_backup<span>Copies the contents of the id_rsa directory into key_backup </span></span>
<span class="codeline">$ rm id_rsa*<span>Deletes the contents of the id_rsa directory</span></span>
</pre>
3. <span class="step-title">Generate a new SSH key.</span>
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.
<pre class="terminal bootcamp">
<span class="codeline">$ ssh-keygen -t rsa -C "<em>your_email@youremail.com</em>"<span>Creates a new ssh key using the provided email</span></span>
<span class="bash-output">Generating public/private rsa key pair.</span>
<span class="bash-output">Enter file in which to save the key (/Users/<em>your_user_directory</em>/.ssh/id_rsa):<em><press enter></em></span>
</pre>
Now you need to enter a passphrase.
<div class="more-info">
<h4 class="compressed">Why do passphrases matter?</h4>
<div class="more-content">
<p>Passwords aren’t very secure, you already know this. If you use one that’s easy to remember, it’s easier to guess or brute-force (try many options until one works). If you use one that’s random it’s hard to remember, and thus you’re more inclined to write the password down. Both of these are Very Bad Things™. This is why you’re using ssh keys.</p>
<p>But using a key without a passphrase is basically the same as writing down that random password in a file on your computer. Anyone who gains access to your drive has gained access to every system you use that key with. This is also a Very Bad Thing™. The solution is obvious: add a passphrase.</p>
<p><em>But I don’t want to enter a long passphrase every time I use the key!</em></p>
<p>Neither do we! Thankfully, there’s a nifty little tool called <code>ssh-agent</code> that can save your passphrase securely so you don’t have to re-enter it. If you’re on OSX Leopard or later your keys can be saved in the system’s keychain to make your life even easier.</p>
<p>For more information about SSH key passphrases, check out our <a href="/working-with-key-passphrases">help guide</a>.</p>
</div>
</div>
<pre class="terminal bootcamp">
<span class="bash-output">Enter passphrase (empty for no passphrase):<em><enter a passphrase></em></span>
<span class="bash-output">Enter same passphrase again:<em><enter passphrase again></em></span>
</pre>
Which should give you something like this:
<pre class="terminal bootcamp">
<span class="bash-output">Your identification has been saved in /Users/<em>your_user_directory</em>/.ssh/id_rsa.</span>
<span class="bash-output">Your public key has been saved in /Users/<em>your_user_directory</em>/.ssh/id_rsa.pub.</span>
<span class="bash-output">The key fingerprint is:</span>
<span class="bash-output">01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db <em>user_name@username.com</em></span>
<span class="bash-output">The key's randomart image is:</span>
<span class="bash-output">+--[ RSA 2048]----+</span>
<span class="bash-output">| .+ + |</span>
<span class="bash-output">| = o O . |</span>
<span class="bash-output">| = * * |</span>
<span class="bash-output">| o = + |</span>
<span class="bash-output">| o S . |</span>
<span class="bash-output">| o o = |</span>
<span class="bash-output">| o . E |</span>
<span class="bash-output">| |</span>
<span class="bash-output">| |</span>
<span class="bash-output">+-----------------+</span>
</pre>
4. <span class="step-title">Add your SSH key to GitHub.</span>
On the GitHub site _Click “Account Settings”_ > _Click “SSH Public Keys”_ > _Click “Add another public key”_
Open the id_rsa.pub file with a text editor (Notepad, TextEdit, or gedit will do just fine). This is your public SSH key. You may need turn on “view hidden files” to find it because the <em>.ssh</em> directory is hidden. <span class="attention">It’s important you copy your SSH key exactly as it is written without adding any newlines or whitespace.</span> Now paste it into the “Key” field.
<div class="more-info">
<h4 class="compressed">Can’t view hidden files? Other ways to copy:</h4>
<div class="more-content">
<h4>OSX</h4>
<pre class="terminal bootcamp">
<span class="codeline">$ pbcopy < ~/.ssh/id_rsa.pub<span>Copies the contents of the id_rsa.pub file to your clipboard</span></span>
</pre>
<h4>Windows</h4>
<p>Unfortunately, there isn’t an easy way to do this from the command line for Windows users. You'll have to use the instructions above.</p>
<h4>Linux</h4>
<pre class="terminal bootcamp">
<span class="codeline">$ sudo apt-get install xclip<span>Downloads and installs xclip</span></span>
<span class="codeline">$ xclip -sel clip < ~/.ssh/id_rsa.pub<span>Copies the contents of the id_rsa.pub file to your clipboard</span></span>
</pre>
</div>
</div>
Now paste it into the “Key” field.
<img src="/images/bootcamp/bootcamp_1_ssh.jpg" width="558" height="402" alt="Paste your SSH Key" />
Hit “Add Key.”
5. <span class="step-title">Test everything out.</span>
To make sure everything is working you’ll now SSH to GitHub. <span class="attention">Don’t change the “git@github.com” part.</span> That’s supposed to be there.
<pre class="terminal bootcamp">
<span class="codeline">$ ssh git@github.com<span>Attempts to ssh to github</span></span>
</pre>
Which should give you this:
<pre class="terminal bootcamp">
<span class="bash-output">The authenticity of host 'github.com (207.97.227.239)' can't be established.</span>
<span class="bash-output">RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.</span>
<span class="bash-output">Are you sure you want to continue connecting (yes/no)?</span>
</pre>
Don’t worry, this is supposed to happen. Type “yes”.
<pre class="terminal bootcamp">
<span class="bash-output">PTY allocation request failed on channel 0</span>
<span class="bash-output">Hi <em>username</em>! You've successfully authenticated, but GitHub does not provide shell access.</span>
<span class="bash-output">Connection to github.com closed.</span>
</pre>
<div class="more-info">
<h4 class="compressed">Having problems?</h4>
<div class="more-content">
<p>Setting up SSH can be problematic some times. Here are some frequent issues people run into:</p>
<h4>SSH to GitHub</h4>
<p>When it came time to run <code>$ ssh git@github.com</code> did you type your own email in there? If you did, you will need to run it again, making sure it says “git@github.com”. This is important because it is the address you are trying to SSH to (GitHub), not your email address.</p>
<h4>Sudo</h4>
<p>Are you using <code>sudo</code>? If you don’t know what that means, then you probably aren’t. If you are using it, stop! You shouldn’t use <code>sudo</code> unless you have a very good reason.</p>
<h4>Agent admitted failure to sign using the key</h4>
<p>This one only seems to happen to Linux users. To solve it, try this:</p>
<pre class="terminal bootcamp">
<span class="codeline">$ ssh-add ~/.ssh/id_rsa<span>Associates your ssh key with ssh-agent</span></span>
</pre>
<p>If that doesn’t solve it, check out <a href="https://bugs.launchpad.net/ubuntu/+source/gnome-keyring/+bug/201786">this thread</a>.</p>
<h4>My connection was refused</h4>
<p>You may be blocked by a firewall. First, you should check your ssh debug info:</p>
<pre class="terminal bootcamp">
<span class="codeline">$ ssh -v git@github.com<span>Prints debug info for the git@github.com SSH connection</span></span>
</pre>
<p>Make sure it is connecting to GitHub on port 22. If it is, check to make sure your firewall is not blocking port 22.</p>
<h4>When all else fails</h4>
<p>If none of these solved your problem, check out <a href="/troubleshooting-ssh">this guide</a> or contact <a href="http://support.github.com/">GitHub support</a></p>
</div>
</div>
|