Sync changes from upstream repository · bitcoinapi/developer.github.com@55592de · GitHub
Skip to content

Commit 55592de

Browse files
author
Hubot
committed
Sync changes from upstream repository
1 parent 54eab23 commit 55592de

6 files changed

Lines changed: 375 additions & 1 deletion

File tree

Lines changed: 120 additions & 0 deletions
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: Using SSH Agent Forwarding | GitHub API
3+
---
4+
5+
# Using SSH agent forwarding
6+
7+
* TOC
8+
{:toc}
9+
10+
SSH agent forwarding can be used to make deploying to a server simple. It allows you to use your local SSH keys instead of leaving keys (without passphrases!) sitting on your server.
11+
12+
If you've already set up an SSH key to interact with GitHub, you're probably familiar with `ssh-agent`. It's a program that runs in the background and keeps your key loaded into memory, so that you don't need to enter your passphrase every time you need to use the key. The nifty thing is, you can choose to let servers access your local `ssh-agent` as if they were already running on the server. This is sort of like asking a friend to enter their password so that you can use their computer.
13+
14+
Check out [Steve Friedl's Tech Tips guide][tech-tips] for a more detailed explanation of SSH agent forwarding.
15+
16+
## Setting up SSH agent forwarding
17+
18+
Ensure that your own SSH key is set up and working. You can use [our guide on generating SSH keys][generating-keys] if you've not done this yet.
19+
20+
You can test that your local key works by entering `ssh -T git@github.com` in the terminal:
21+
22+
<pre class="terminal">
23+
$ ssh -T git@github.com
24+
<span class="comment"># Attempt to SSH in to github</span>
25+
<span class="output">Hi <em>username</em>! You've successfully authenticated, but GitHub does not provide</span>
26+
<span class="output">shell access.</span>
27+
</pre>
28+
29+
We're off to a great start. Let's set up SSH to allow agent forwarding to your server.
30+
31+
1. Using your favorite text editor, open up the file at `~/.ssh/config`. If this file doesn't exist, you can create it by entering `touch ~/.ssh/config` in the terminal.
32+
33+
2. Enter the following text into the file, replacing `example.com` with your server's domain name or IP:
34+
35+
Host example.com
36+
ForwardAgent yes
37+
38+
<div class="warning">
39+
<p>
40+
<strong>Warning</strong>: You may be tempted to use a wildcard like <code>Host *</code> to just apply this setting to all SSH connections. That's not really a good idea, as you'd be sharing your local SSH keys with <em>every</em> server you SSH into. They won't have direct access to the keys, but they will be able to use them <em>as you</em> while the connection is established. <strong>You should only add servers you trust and that you intend to use with agent forwarding.</strong>
41+
</p>
42+
</div>
43+
44+
## Testing SSH agent forwarding
45+
46+
To test that agent forwarding is working with your server, you can SSH into your server and run `ssh -T git@github.com` once more. If all is well, you'll get back the same prompt as you did locally.
47+
48+
If you're unsure if your local key is being used, you can also inspect the `SSH_AUTH_SOCK` variable on your server:
49+
50+
<pre class="terminal">
51+
$ echo "$SSH_AUTH_SOCK"
52+
<span class="comment"># Print out the SSH_AUTH_SOCK variable</span>
53+
<span class="output">/tmp/ssh-4hNGMk8AZX/agent.79453</span>
54+
</pre>
55+
56+
If the variable is not set, it means that agent forwarding is not working:
57+
58+
<pre class="terminal">
59+
$ echo "$SSH_AUTH_SOCK"
60+
<span class="comment"># Print out the SSH_AUTH_SOCK variable</span>
61+
<span class="output"><em>[No output]</em></span>
62+
$ ssh -T git@github.com
63+
<span class="comment"># Try to SSH to github</span>
64+
<span class="output">Permission denied (publickey).</span>
65+
</pre>
66+
67+
## Troubleshooting SSH agent forwarding
68+
69+
Here are some things to look out for when troubleshooting SSH agent forwarding.
70+
71+
### Your SSH keys must work locally
72+
73+
Before you can make your keys work through agent forwarding, they must work locally first. [Our guide on generating SSH keys][generating-keys] can help you set up your SSH keys locally.
74+
75+
### Your system must allow SSH agent forwarding
76+
77+
Sometimes, system configurations disallow SSH agent forwarding. You can check if a system configuration file is being used by entering the following command in the terminal:
78+
79+
<pre class="terminal">
80+
$ ssh -v <em>example.com</em>
81+
<span class="comment"># Connect to example.com with verbose debug output</span>
82+
<span class="output">OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011</span>
83+
<span class="output">debug1: Reading configuration data /Users/<em>you</em>/.ssh/config</span>
84+
<span class="output">debug1: Applying options for example.com</span>
85+
<span class="output">debug1: Reading configuration data /etc/ssh_config</span>
86+
<span class="output">debug1: Applying options for *</span>
87+
$ exit
88+
<span class="comment"># Returns to your local command prompt</span>
89+
</pre>
90+
91+
In the example above, the file *~/.ssh/config* is loaded first, then */etc/ssh_config* is read. We can inspect that file to see if it's overriding our options by running the following commands:
92+
93+
<pre class="terminal">
94+
$ cat /etc/ssh_config
95+
<span class="comment"># Print out the /etc/ssh_config file</span>
96+
<span class="output"> Host *</span>
97+
<span class="output"> SendEnv LANG LC_*</span>
98+
<span class="output"> ForwardAgent no</span>
99+
</pre>
100+
101+
In this example, our */etc/ssh_config* file specifically says `ForwardAgent no`, which is a way to block agent forwarding. Deleting this line from the file should get agent forwarding working once more.
102+
103+
### Your server must allow SSH agent forwarding on inbound connections
104+
105+
Agent forwarding may also be blocked on your server. You can check that agent forwarding is permitted by SSHing into the server and running `sshd_config`. The output from this command should indicate that `AllowAgentForwarding` is set.
106+
107+
### Your local `ssh-agent` must be running
108+
109+
On most computers, the operating system automatically launches `ssh-agent` for you. On Windows, however, you need to do this manually. We have [a guide on how to start `ssh-agent` whenever you open Git Bash][autolaunch-ssh-agent].
110+
111+
To verify that `ssh-agent` is running on your computer, type the following command in the terminal:
112+
113+
<pre class="terminal">
114+
$ echo "$SSH_AUTH_SOCK"
115+
<span class="comment"># Print out the SSH_AUTH_SOCK variable</span>
116+
<span class="output">/tmp/launch-kNSlgU/Listeners</span>
117+
</pre>
118+
119+
### Your key must be available to `ssh-agent`
120+
121+
You can check that your key is visible to `ssh-agent` by running the following command:
122+
123+
<pre class="terminal">
124+
ssh-add -L
125+
</pre>
126+
127+
If the command says that no identity is available, you'll need to add your key:
128+
129+
<pre class="terminal">
130+
ssh-add <em>yourkey</em>
131+
</pre>
132+
133+
[tech-tips]: http://www.unixwiz.net/techtips/ssh-agent-forwarding.html
134+
[generating-keys]: https://help.github.com/articles/generating-ssh-keys
135+
[ssh-passphrases]: https://help.github.com/ssh-key-passphrases/
136+
[autolaunch-ssh-agent]: https://help.github.com/articles/working-with-ssh-key-passphrases#auto-launching-ssh-agent-on-msysgit

layouts/guides.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ <h2><a href="/v3/">API</a></h2>
3030
<li><h3><a href="/guides/traversing-with-pagination/">Traversing with pagination</a></h3></li>
3131
<li><h3><a href="/guides/building-a-ci-server/">Building a CI server</a></h3></li>
3232
<li><h3><a href="/guides/delivering-deployments/">Delivering deployments</a></h3></li>
33+
<li><h3><a href="/guides/managing-deploy-keys/">Managing deploy keys</a></h3></li>
34+
<li><h3><a href="/guides/using-ssh-agent-forwarding/">Using SSH agent forwarding</a></h3></li>
3335
</ul>
3436
</div>
3537

static/css/documentation.css

Lines changed: 93 additions & 1 deletion

static/images/deploy-keys.png

24.5 KB
Loading

0 commit comments

Comments
 (0)