How can I get ssh-agent working over ssh and in tmux (on OS X)?tmux: Cannot SSH from inside tmux, even though...
Is it a Cyclops number? "Nobody" knows!
Under what conditions would I NOT add my Proficiency Bonus to a Spell Attack Roll (or Saving Throw DC)?
What is Tony Stark injecting into himself in Iron Man 3?
Why would the IRS ask for birth certificates or even audit a small tax return?
Create chunks from an array
How to make sure I'm assertive enough in contact with subordinates?
Giving a talk in my old university, how prominently should I tell students my salary?
Does the in-code argument passing conventions used on PDP-11's have a name?
Quitting employee has privileged access to critical information
Is there such a thing in math the inverse of a sequence?
Is there a way to find out the age of climbing ropes?
Is there a math equivalent to the conditional ternary operator?
How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?
Why can't we use freedom of speech and expression to incite people to rebel against government in India?
School performs periodic password audits. Is my password compromised?
Does the US political system, in principle, allow for a no-party system?
Why are special aircraft used for the carriers in the United States Navy?
Did Amazon pay $0 in taxes last year?
How spaceships determine each other's mass in space?
Is "cogitate" an appropriate word for this?
Are there other characters in the Star Wars universe who had damaged bodies and needed to wear an outfit like Darth Vader?
An Undercover Army
Can inspiration allow the Rogue to make a Sneak Attack?
Computing the volume of a simplex-like object with constraints
How can I get ssh-agent working over ssh and in tmux (on OS X)?
tmux: Cannot SSH from inside tmux, even though I have agent-forwarding (ssh -A) onssh-agent and screenIs it possible to spawn an ssh-agent for a new tmux session?When I SSH into OS X, I don't have my keychain. When I use Terminal, I doProblem with ssh-agent and/or Mac keychain on Mactmux: Cannot SSH from inside tmux, even though I have agent-forwarding (ssh -A) onMac terminal keeps using SSH key with same fingerprint when running git cloneSSH 'Host key verification failed' errorCan't Get libpam-ssh-agent-auth Working In Ubuntu 13.10Did I just send my private ssh key?SSH private and public key creation and setupHow can I cache Yubikey/U2F credentials when authenticating over SSH (specifically Git)?ssh-agent only works as command and not in a script in macOS
I have a private key set up for my github account, the passphrase to which is, I believe, stored in OS X's keychain. I certainly don't have to type it in when I open a terminal window and enter ssh git@github.com
.
However, when I'm running bash over an ssh session, or locally inside a tmux session, I have to type in the passphrase every single time I attempt to ssh to github.
This question suggests that a similar problem exists with screen, but I don't really understand the issue well enough to fix it in tmux. There's also this page which includes a fairly complicated solution, but for zsh.
EDIT:
In response to @Mikel's answer, from a local terminal I get the following output:
[~]
$ echo $SSH_AUTH_SOCK
/tmp/launch-S4HBD6/Listeners
[~]
$ ssh-add -l
2048 [my key fingerprint] /Users/richie/.ssh/id_rsa (RSA)
[~]
$ typeset -p SSH_AUTH_SOCK
declare -x SSH_AUTH_SOCK="/tmp/launch-S4HBD6/Listeners"
Whereas over ssh or in tmux I get:
[~]
$ echo $SSH_AUTH_SOCK
[~]
$ ssh-add -l
Could not open a connection to your authentication agent.
[~]
$ typeset -p SSH_AUTH_SOCK
bash: typeset: SSH_AUTH_SOCK: not found
echo $SSH_AGENT_PID
returns nothing whatever shell I run it from.
macos ssh tmux ssh-agent
|
show 1 more comment
I have a private key set up for my github account, the passphrase to which is, I believe, stored in OS X's keychain. I certainly don't have to type it in when I open a terminal window and enter ssh git@github.com
.
However, when I'm running bash over an ssh session, or locally inside a tmux session, I have to type in the passphrase every single time I attempt to ssh to github.
This question suggests that a similar problem exists with screen, but I don't really understand the issue well enough to fix it in tmux. There's also this page which includes a fairly complicated solution, but for zsh.
EDIT:
In response to @Mikel's answer, from a local terminal I get the following output:
[~]
$ echo $SSH_AUTH_SOCK
/tmp/launch-S4HBD6/Listeners
[~]
$ ssh-add -l
2048 [my key fingerprint] /Users/richie/.ssh/id_rsa (RSA)
[~]
$ typeset -p SSH_AUTH_SOCK
declare -x SSH_AUTH_SOCK="/tmp/launch-S4HBD6/Listeners"
Whereas over ssh or in tmux I get:
[~]
$ echo $SSH_AUTH_SOCK
[~]
$ ssh-add -l
Could not open a connection to your authentication agent.
[~]
$ typeset -p SSH_AUTH_SOCK
bash: typeset: SSH_AUTH_SOCK: not found
echo $SSH_AGENT_PID
returns nothing whatever shell I run it from.
macos ssh tmux ssh-agent
What abouttypeset -p SSH_AUTH_SOCK
?
– Mikel
Jan 27 '11 at 11:18
@Mikelbash: typeset: SSH_AUTH_SOCK: not found
from within ssh/tmux. I'll try it locally tonight, if necessary.
– Rich
Jan 27 '11 at 12:53
@Mikel I've added that command's output to the question.
– Rich
Jan 27 '11 at 20:33
AFAIK, question and answers are not OS X-specific. That's relevant to avoid some non-OS X-specific dups, namely superuser.com/q/334975/46794 and superuser.com/q/479796/46794.
– Blaisorblade
Sep 19 '13 at 8:33
@Blaisorblade I was under the impression my passphrase was stored in the OS X keychain (Although I can't remember now why I believed that to be the case). Is that incorrect?
– Rich
Sep 19 '13 at 8:52
|
show 1 more comment
I have a private key set up for my github account, the passphrase to which is, I believe, stored in OS X's keychain. I certainly don't have to type it in when I open a terminal window and enter ssh git@github.com
.
However, when I'm running bash over an ssh session, or locally inside a tmux session, I have to type in the passphrase every single time I attempt to ssh to github.
This question suggests that a similar problem exists with screen, but I don't really understand the issue well enough to fix it in tmux. There's also this page which includes a fairly complicated solution, but for zsh.
EDIT:
In response to @Mikel's answer, from a local terminal I get the following output:
[~]
$ echo $SSH_AUTH_SOCK
/tmp/launch-S4HBD6/Listeners
[~]
$ ssh-add -l
2048 [my key fingerprint] /Users/richie/.ssh/id_rsa (RSA)
[~]
$ typeset -p SSH_AUTH_SOCK
declare -x SSH_AUTH_SOCK="/tmp/launch-S4HBD6/Listeners"
Whereas over ssh or in tmux I get:
[~]
$ echo $SSH_AUTH_SOCK
[~]
$ ssh-add -l
Could not open a connection to your authentication agent.
[~]
$ typeset -p SSH_AUTH_SOCK
bash: typeset: SSH_AUTH_SOCK: not found
echo $SSH_AGENT_PID
returns nothing whatever shell I run it from.
macos ssh tmux ssh-agent
I have a private key set up for my github account, the passphrase to which is, I believe, stored in OS X's keychain. I certainly don't have to type it in when I open a terminal window and enter ssh git@github.com
.
However, when I'm running bash over an ssh session, or locally inside a tmux session, I have to type in the passphrase every single time I attempt to ssh to github.
This question suggests that a similar problem exists with screen, but I don't really understand the issue well enough to fix it in tmux. There's also this page which includes a fairly complicated solution, but for zsh.
EDIT:
In response to @Mikel's answer, from a local terminal I get the following output:
[~]
$ echo $SSH_AUTH_SOCK
/tmp/launch-S4HBD6/Listeners
[~]
$ ssh-add -l
2048 [my key fingerprint] /Users/richie/.ssh/id_rsa (RSA)
[~]
$ typeset -p SSH_AUTH_SOCK
declare -x SSH_AUTH_SOCK="/tmp/launch-S4HBD6/Listeners"
Whereas over ssh or in tmux I get:
[~]
$ echo $SSH_AUTH_SOCK
[~]
$ ssh-add -l
Could not open a connection to your authentication agent.
[~]
$ typeset -p SSH_AUTH_SOCK
bash: typeset: SSH_AUTH_SOCK: not found
echo $SSH_AGENT_PID
returns nothing whatever shell I run it from.
macos ssh tmux ssh-agent
macos ssh tmux ssh-agent
edited Mar 20 '17 at 10:17
Community♦
1
1
asked Jan 25 '11 at 22:25
RichRich
1,21521126
1,21521126
What abouttypeset -p SSH_AUTH_SOCK
?
– Mikel
Jan 27 '11 at 11:18
@Mikelbash: typeset: SSH_AUTH_SOCK: not found
from within ssh/tmux. I'll try it locally tonight, if necessary.
– Rich
Jan 27 '11 at 12:53
@Mikel I've added that command's output to the question.
– Rich
Jan 27 '11 at 20:33
AFAIK, question and answers are not OS X-specific. That's relevant to avoid some non-OS X-specific dups, namely superuser.com/q/334975/46794 and superuser.com/q/479796/46794.
– Blaisorblade
Sep 19 '13 at 8:33
@Blaisorblade I was under the impression my passphrase was stored in the OS X keychain (Although I can't remember now why I believed that to be the case). Is that incorrect?
– Rich
Sep 19 '13 at 8:52
|
show 1 more comment
What abouttypeset -p SSH_AUTH_SOCK
?
– Mikel
Jan 27 '11 at 11:18
@Mikelbash: typeset: SSH_AUTH_SOCK: not found
from within ssh/tmux. I'll try it locally tonight, if necessary.
– Rich
Jan 27 '11 at 12:53
@Mikel I've added that command's output to the question.
– Rich
Jan 27 '11 at 20:33
AFAIK, question and answers are not OS X-specific. That's relevant to avoid some non-OS X-specific dups, namely superuser.com/q/334975/46794 and superuser.com/q/479796/46794.
– Blaisorblade
Sep 19 '13 at 8:33
@Blaisorblade I was under the impression my passphrase was stored in the OS X keychain (Although I can't remember now why I believed that to be the case). Is that incorrect?
– Rich
Sep 19 '13 at 8:52
What about
typeset -p SSH_AUTH_SOCK
?– Mikel
Jan 27 '11 at 11:18
What about
typeset -p SSH_AUTH_SOCK
?– Mikel
Jan 27 '11 at 11:18
@Mikel
bash: typeset: SSH_AUTH_SOCK: not found
from within ssh/tmux. I'll try it locally tonight, if necessary.– Rich
Jan 27 '11 at 12:53
@Mikel
bash: typeset: SSH_AUTH_SOCK: not found
from within ssh/tmux. I'll try it locally tonight, if necessary.– Rich
Jan 27 '11 at 12:53
@Mikel I've added that command's output to the question.
– Rich
Jan 27 '11 at 20:33
@Mikel I've added that command's output to the question.
– Rich
Jan 27 '11 at 20:33
AFAIK, question and answers are not OS X-specific. That's relevant to avoid some non-OS X-specific dups, namely superuser.com/q/334975/46794 and superuser.com/q/479796/46794.
– Blaisorblade
Sep 19 '13 at 8:33
AFAIK, question and answers are not OS X-specific. That's relevant to avoid some non-OS X-specific dups, namely superuser.com/q/334975/46794 and superuser.com/q/479796/46794.
– Blaisorblade
Sep 19 '13 at 8:33
@Blaisorblade I was under the impression my passphrase was stored in the OS X keychain (Although I can't remember now why I believed that to be the case). Is that incorrect?
– Rich
Sep 19 '13 at 8:52
@Blaisorblade I was under the impression my passphrase was stored in the OS X keychain (Although I can't remember now why I believed that to be the case). Is that incorrect?
– Rich
Sep 19 '13 at 8:52
|
show 1 more comment
7 Answers
7
active
oldest
votes
My colleague created some bash functions to assist with finding a live agent: https://github.com/wwalker/ssh-find-agent
He uses it mainly for connecting between systems (laptop to desktop, etc), but I use it most often for local tmux sessions where you logout/in from your window manager (OS X for myself).
Usage
Download ssh-find-agent.bash (
git clone git://github.com/wwalker/ssh-find-agent.git
works).
Add the following to ~/.bashrc:
. /path/to/ssh-find-agent.bash
Then you can type the following to set SSH_AUTH_SOCK in your current shell:
set_ssh_agent_socket
I accepted this answer rather than any of the others that might work because it doesn't required SSH agent forwarding, which is better for my purposes. Thanks!
– Rich
Feb 5 '14 at 0:00
add a comment |
An elegant solution, picked up from dagit.o:
Create ~/.ssh/rc
#!/bin/bash
if [ -S "$SSH_AUTH_SOCK" ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi
Add to ~/.tmux.conf
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
set-environment -g 'SSH_AUTH_SOCK' ~/.ssh/ssh_auth_sock
add a comment |
In your .tmux.conf
configuration file, add this line:
set -g update-environment "SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"
This causes these environment variables to be copied from your main shell to any shells opened within tmux, which then allows ssh-agent to work properly within those tmux shells.
2
This is the appropriate method for getting those values into a tmux session, but all of those environment variables should already be included in the default value ofupdate-environment
. The OP should check theirupdate-environment
value and possibly update wherever it is already being changed.
– Chris Johnsen
Feb 19 '12 at 5:35
1
Hm.. after digging further, I agree -- the settings I listed are already in the defaults, and if I run tmux without a .tmux.conf file, everything works properly. And if I remove the line I quoted from my .tmux.conf file, that is working for me as well, although it didn't before. There's clearly something else going wrong occasionally. Maybe to do with suspend/restore or attach/detach or sshing into a tmux session remotely. I'll keep my eyes open and update if I find the factor which makes it reproducible.
– Trevor Powell
Feb 19 '12 at 6:43
update-environment
is set correctly. However, the problem still occurs.
– Rich
Mar 23 '12 at 10:33
2
The problem with this is that config will only be re-executed when notmux
server is present, defying the purpose of re-attaching... Maybe there is a command line switch to re-update those variables?
– Tobias Kienzler
Nov 6 '13 at 13:45
add a comment |
It happened to me that panes created when connecting via ssh from OS X started asking my passphrase after a while of working ok. I found a way to fix that stealing this line from http://santini.di.unimi.it/extras/ph/my-tmux-setup.html
eval $(tmux show-environment -t [YOUR-SESSION] | grep '^SSH_AUTH_SOCK')
Just run it from the pane that's complaining.
add a comment |
Not sure if you are using bash or another shell, but this guy's tmux setup looks like it would work for bash. Personally, I am using zsh with oh-my-zsh, and I found that ssh-agent started working in tmux after I added
zstyle :omz:plugins:ssh-agent agent-forwarding on
to my .zshrc file and reloaded the config in my running zsh sessions. I also found this guy's zsh-oriented solution, but it turned out to be unnecessary for me.
add a comment |
What does:
echo $SSH_AUTH_SOCK
echo $SSH_AGENT_PID
ssh-add -l
print?
Run it in your normal terminal, then run it inside your tmux
session. They should print the same thing.
I added the response to these commands to the question. I've also realised that the problem also occurs when I login over ssh (without using tmux), and have edited the question accordingly.
– Rich
Jan 27 '11 at 9:56
4
ssh
is easy. Turn agent forwarding on. Easiest way to do that is runssh -A
instead ofssh
. Use an alias so you don't have to type it every time, or put it in your.SSH/config
.
– Mikel
Jan 27 '11 at 22:37
Cool, thanks. That worked for ssh. Any ideas how to fix it in tmux?
– Rich
Feb 1 '11 at 17:38
add a comment |
There are many solutions, but the simplest one is found in Hans Ginzel's answer, dated 8 January 2016, to a related StackOverflow question dated 27 January 2014. Simply add the following to your shell ~/.profile
or similar:
alias ssh='eval $(tmux show-env -s | grep "^SSH_") && ssh'
There is no need to define multi-line functions or create new temporary files. If you don't want to alias ssh
, simply change it to fixssh
and remove && ssh
at the end, and run fixssh
whenever you're trying to run ssh
from inside a reattached tmux session.
The answer by Hans Ginzel suggests that a 'newer version' of tmux is required to run show-env -s
. This works for me in tmux 2.7, and on my reading of the changelog, -s
was added on 3 June 2008 just before the release of tmux 0.3. tmux 2.3 (29 September 2016) is in Debian stable.
New contributor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f237822%2fhow-can-i-get-ssh-agent-working-over-ssh-and-in-tmux-on-os-x%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
My colleague created some bash functions to assist with finding a live agent: https://github.com/wwalker/ssh-find-agent
He uses it mainly for connecting between systems (laptop to desktop, etc), but I use it most often for local tmux sessions where you logout/in from your window manager (OS X for myself).
Usage
Download ssh-find-agent.bash (
git clone git://github.com/wwalker/ssh-find-agent.git
works).
Add the following to ~/.bashrc:
. /path/to/ssh-find-agent.bash
Then you can type the following to set SSH_AUTH_SOCK in your current shell:
set_ssh_agent_socket
I accepted this answer rather than any of the others that might work because it doesn't required SSH agent forwarding, which is better for my purposes. Thanks!
– Rich
Feb 5 '14 at 0:00
add a comment |
My colleague created some bash functions to assist with finding a live agent: https://github.com/wwalker/ssh-find-agent
He uses it mainly for connecting between systems (laptop to desktop, etc), but I use it most often for local tmux sessions where you logout/in from your window manager (OS X for myself).
Usage
Download ssh-find-agent.bash (
git clone git://github.com/wwalker/ssh-find-agent.git
works).
Add the following to ~/.bashrc:
. /path/to/ssh-find-agent.bash
Then you can type the following to set SSH_AUTH_SOCK in your current shell:
set_ssh_agent_socket
I accepted this answer rather than any of the others that might work because it doesn't required SSH agent forwarding, which is better for my purposes. Thanks!
– Rich
Feb 5 '14 at 0:00
add a comment |
My colleague created some bash functions to assist with finding a live agent: https://github.com/wwalker/ssh-find-agent
He uses it mainly for connecting between systems (laptop to desktop, etc), but I use it most often for local tmux sessions where you logout/in from your window manager (OS X for myself).
Usage
Download ssh-find-agent.bash (
git clone git://github.com/wwalker/ssh-find-agent.git
works).
Add the following to ~/.bashrc:
. /path/to/ssh-find-agent.bash
Then you can type the following to set SSH_AUTH_SOCK in your current shell:
set_ssh_agent_socket
My colleague created some bash functions to assist with finding a live agent: https://github.com/wwalker/ssh-find-agent
He uses it mainly for connecting between systems (laptop to desktop, etc), but I use it most often for local tmux sessions where you logout/in from your window manager (OS X for myself).
Usage
Download ssh-find-agent.bash (
git clone git://github.com/wwalker/ssh-find-agent.git
works).
Add the following to ~/.bashrc:
. /path/to/ssh-find-agent.bash
Then you can type the following to set SSH_AUTH_SOCK in your current shell:
set_ssh_agent_socket
edited Nov 8 '11 at 1:28
3498DB
15.8k114762
15.8k114762
answered Nov 7 '11 at 23:24
user104502user104502
862
862
I accepted this answer rather than any of the others that might work because it doesn't required SSH agent forwarding, which is better for my purposes. Thanks!
– Rich
Feb 5 '14 at 0:00
add a comment |
I accepted this answer rather than any of the others that might work because it doesn't required SSH agent forwarding, which is better for my purposes. Thanks!
– Rich
Feb 5 '14 at 0:00
I accepted this answer rather than any of the others that might work because it doesn't required SSH agent forwarding, which is better for my purposes. Thanks!
– Rich
Feb 5 '14 at 0:00
I accepted this answer rather than any of the others that might work because it doesn't required SSH agent forwarding, which is better for my purposes. Thanks!
– Rich
Feb 5 '14 at 0:00
add a comment |
An elegant solution, picked up from dagit.o:
Create ~/.ssh/rc
#!/bin/bash
if [ -S "$SSH_AUTH_SOCK" ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi
Add to ~/.tmux.conf
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
set-environment -g 'SSH_AUTH_SOCK' ~/.ssh/ssh_auth_sock
add a comment |
An elegant solution, picked up from dagit.o:
Create ~/.ssh/rc
#!/bin/bash
if [ -S "$SSH_AUTH_SOCK" ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi
Add to ~/.tmux.conf
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
set-environment -g 'SSH_AUTH_SOCK' ~/.ssh/ssh_auth_sock
add a comment |
An elegant solution, picked up from dagit.o:
Create ~/.ssh/rc
#!/bin/bash
if [ -S "$SSH_AUTH_SOCK" ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi
Add to ~/.tmux.conf
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
set-environment -g 'SSH_AUTH_SOCK' ~/.ssh/ssh_auth_sock
An elegant solution, picked up from dagit.o:
Create ~/.ssh/rc
#!/bin/bash
if [ -S "$SSH_AUTH_SOCK" ]; then
ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock
fi
Add to ~/.tmux.conf
set -g update-environment "DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
set-environment -g 'SSH_AUTH_SOCK' ~/.ssh/ssh_auth_sock
edited Jul 10 '13 at 18:00
answered Jul 10 '13 at 11:54
mislavmislav
1,5401119
1,5401119
add a comment |
add a comment |
In your .tmux.conf
configuration file, add this line:
set -g update-environment "SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"
This causes these environment variables to be copied from your main shell to any shells opened within tmux, which then allows ssh-agent to work properly within those tmux shells.
2
This is the appropriate method for getting those values into a tmux session, but all of those environment variables should already be included in the default value ofupdate-environment
. The OP should check theirupdate-environment
value and possibly update wherever it is already being changed.
– Chris Johnsen
Feb 19 '12 at 5:35
1
Hm.. after digging further, I agree -- the settings I listed are already in the defaults, and if I run tmux without a .tmux.conf file, everything works properly. And if I remove the line I quoted from my .tmux.conf file, that is working for me as well, although it didn't before. There's clearly something else going wrong occasionally. Maybe to do with suspend/restore or attach/detach or sshing into a tmux session remotely. I'll keep my eyes open and update if I find the factor which makes it reproducible.
– Trevor Powell
Feb 19 '12 at 6:43
update-environment
is set correctly. However, the problem still occurs.
– Rich
Mar 23 '12 at 10:33
2
The problem with this is that config will only be re-executed when notmux
server is present, defying the purpose of re-attaching... Maybe there is a command line switch to re-update those variables?
– Tobias Kienzler
Nov 6 '13 at 13:45
add a comment |
In your .tmux.conf
configuration file, add this line:
set -g update-environment "SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"
This causes these environment variables to be copied from your main shell to any shells opened within tmux, which then allows ssh-agent to work properly within those tmux shells.
2
This is the appropriate method for getting those values into a tmux session, but all of those environment variables should already be included in the default value ofupdate-environment
. The OP should check theirupdate-environment
value and possibly update wherever it is already being changed.
– Chris Johnsen
Feb 19 '12 at 5:35
1
Hm.. after digging further, I agree -- the settings I listed are already in the defaults, and if I run tmux without a .tmux.conf file, everything works properly. And if I remove the line I quoted from my .tmux.conf file, that is working for me as well, although it didn't before. There's clearly something else going wrong occasionally. Maybe to do with suspend/restore or attach/detach or sshing into a tmux session remotely. I'll keep my eyes open and update if I find the factor which makes it reproducible.
– Trevor Powell
Feb 19 '12 at 6:43
update-environment
is set correctly. However, the problem still occurs.
– Rich
Mar 23 '12 at 10:33
2
The problem with this is that config will only be re-executed when notmux
server is present, defying the purpose of re-attaching... Maybe there is a command line switch to re-update those variables?
– Tobias Kienzler
Nov 6 '13 at 13:45
add a comment |
In your .tmux.conf
configuration file, add this line:
set -g update-environment "SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"
This causes these environment variables to be copied from your main shell to any shells opened within tmux, which then allows ssh-agent to work properly within those tmux shells.
In your .tmux.conf
configuration file, add this line:
set -g update-environment "SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"
This causes these environment variables to be copied from your main shell to any shells opened within tmux, which then allows ssh-agent to work properly within those tmux shells.
answered Feb 18 '12 at 8:13
Trevor PowellTrevor Powell
50058
50058
2
This is the appropriate method for getting those values into a tmux session, but all of those environment variables should already be included in the default value ofupdate-environment
. The OP should check theirupdate-environment
value and possibly update wherever it is already being changed.
– Chris Johnsen
Feb 19 '12 at 5:35
1
Hm.. after digging further, I agree -- the settings I listed are already in the defaults, and if I run tmux without a .tmux.conf file, everything works properly. And if I remove the line I quoted from my .tmux.conf file, that is working for me as well, although it didn't before. There's clearly something else going wrong occasionally. Maybe to do with suspend/restore or attach/detach or sshing into a tmux session remotely. I'll keep my eyes open and update if I find the factor which makes it reproducible.
– Trevor Powell
Feb 19 '12 at 6:43
update-environment
is set correctly. However, the problem still occurs.
– Rich
Mar 23 '12 at 10:33
2
The problem with this is that config will only be re-executed when notmux
server is present, defying the purpose of re-attaching... Maybe there is a command line switch to re-update those variables?
– Tobias Kienzler
Nov 6 '13 at 13:45
add a comment |
2
This is the appropriate method for getting those values into a tmux session, but all of those environment variables should already be included in the default value ofupdate-environment
. The OP should check theirupdate-environment
value and possibly update wherever it is already being changed.
– Chris Johnsen
Feb 19 '12 at 5:35
1
Hm.. after digging further, I agree -- the settings I listed are already in the defaults, and if I run tmux without a .tmux.conf file, everything works properly. And if I remove the line I quoted from my .tmux.conf file, that is working for me as well, although it didn't before. There's clearly something else going wrong occasionally. Maybe to do with suspend/restore or attach/detach or sshing into a tmux session remotely. I'll keep my eyes open and update if I find the factor which makes it reproducible.
– Trevor Powell
Feb 19 '12 at 6:43
update-environment
is set correctly. However, the problem still occurs.
– Rich
Mar 23 '12 at 10:33
2
The problem with this is that config will only be re-executed when notmux
server is present, defying the purpose of re-attaching... Maybe there is a command line switch to re-update those variables?
– Tobias Kienzler
Nov 6 '13 at 13:45
2
2
This is the appropriate method for getting those values into a tmux session, but all of those environment variables should already be included in the default value of
update-environment
. The OP should check their update-environment
value and possibly update wherever it is already being changed.– Chris Johnsen
Feb 19 '12 at 5:35
This is the appropriate method for getting those values into a tmux session, but all of those environment variables should already be included in the default value of
update-environment
. The OP should check their update-environment
value and possibly update wherever it is already being changed.– Chris Johnsen
Feb 19 '12 at 5:35
1
1
Hm.. after digging further, I agree -- the settings I listed are already in the defaults, and if I run tmux without a .tmux.conf file, everything works properly. And if I remove the line I quoted from my .tmux.conf file, that is working for me as well, although it didn't before. There's clearly something else going wrong occasionally. Maybe to do with suspend/restore or attach/detach or sshing into a tmux session remotely. I'll keep my eyes open and update if I find the factor which makes it reproducible.
– Trevor Powell
Feb 19 '12 at 6:43
Hm.. after digging further, I agree -- the settings I listed are already in the defaults, and if I run tmux without a .tmux.conf file, everything works properly. And if I remove the line I quoted from my .tmux.conf file, that is working for me as well, although it didn't before. There's clearly something else going wrong occasionally. Maybe to do with suspend/restore or attach/detach or sshing into a tmux session remotely. I'll keep my eyes open and update if I find the factor which makes it reproducible.
– Trevor Powell
Feb 19 '12 at 6:43
update-environment
is set correctly. However, the problem still occurs.– Rich
Mar 23 '12 at 10:33
update-environment
is set correctly. However, the problem still occurs.– Rich
Mar 23 '12 at 10:33
2
2
The problem with this is that config will only be re-executed when no
tmux
server is present, defying the purpose of re-attaching... Maybe there is a command line switch to re-update those variables?– Tobias Kienzler
Nov 6 '13 at 13:45
The problem with this is that config will only be re-executed when no
tmux
server is present, defying the purpose of re-attaching... Maybe there is a command line switch to re-update those variables?– Tobias Kienzler
Nov 6 '13 at 13:45
add a comment |
It happened to me that panes created when connecting via ssh from OS X started asking my passphrase after a while of working ok. I found a way to fix that stealing this line from http://santini.di.unimi.it/extras/ph/my-tmux-setup.html
eval $(tmux show-environment -t [YOUR-SESSION] | grep '^SSH_AUTH_SOCK')
Just run it from the pane that's complaining.
add a comment |
It happened to me that panes created when connecting via ssh from OS X started asking my passphrase after a while of working ok. I found a way to fix that stealing this line from http://santini.di.unimi.it/extras/ph/my-tmux-setup.html
eval $(tmux show-environment -t [YOUR-SESSION] | grep '^SSH_AUTH_SOCK')
Just run it from the pane that's complaining.
add a comment |
It happened to me that panes created when connecting via ssh from OS X started asking my passphrase after a while of working ok. I found a way to fix that stealing this line from http://santini.di.unimi.it/extras/ph/my-tmux-setup.html
eval $(tmux show-environment -t [YOUR-SESSION] | grep '^SSH_AUTH_SOCK')
Just run it from the pane that's complaining.
It happened to me that panes created when connecting via ssh from OS X started asking my passphrase after a while of working ok. I found a way to fix that stealing this line from http://santini.di.unimi.it/extras/ph/my-tmux-setup.html
eval $(tmux show-environment -t [YOUR-SESSION] | grep '^SSH_AUTH_SOCK')
Just run it from the pane that's complaining.
answered Jun 12 '14 at 15:47
user1153623user1153623
311
311
add a comment |
add a comment |
Not sure if you are using bash or another shell, but this guy's tmux setup looks like it would work for bash. Personally, I am using zsh with oh-my-zsh, and I found that ssh-agent started working in tmux after I added
zstyle :omz:plugins:ssh-agent agent-forwarding on
to my .zshrc file and reloaded the config in my running zsh sessions. I also found this guy's zsh-oriented solution, but it turned out to be unnecessary for me.
add a comment |
Not sure if you are using bash or another shell, but this guy's tmux setup looks like it would work for bash. Personally, I am using zsh with oh-my-zsh, and I found that ssh-agent started working in tmux after I added
zstyle :omz:plugins:ssh-agent agent-forwarding on
to my .zshrc file and reloaded the config in my running zsh sessions. I also found this guy's zsh-oriented solution, but it turned out to be unnecessary for me.
add a comment |
Not sure if you are using bash or another shell, but this guy's tmux setup looks like it would work for bash. Personally, I am using zsh with oh-my-zsh, and I found that ssh-agent started working in tmux after I added
zstyle :omz:plugins:ssh-agent agent-forwarding on
to my .zshrc file and reloaded the config in my running zsh sessions. I also found this guy's zsh-oriented solution, but it turned out to be unnecessary for me.
Not sure if you are using bash or another shell, but this guy's tmux setup looks like it would work for bash. Personally, I am using zsh with oh-my-zsh, and I found that ssh-agent started working in tmux after I added
zstyle :omz:plugins:ssh-agent agent-forwarding on
to my .zshrc file and reloaded the config in my running zsh sessions. I also found this guy's zsh-oriented solution, but it turned out to be unnecessary for me.
answered Aug 5 '11 at 18:39
cwjohnstoncwjohnston
1312
1312
add a comment |
add a comment |
What does:
echo $SSH_AUTH_SOCK
echo $SSH_AGENT_PID
ssh-add -l
print?
Run it in your normal terminal, then run it inside your tmux
session. They should print the same thing.
I added the response to these commands to the question. I've also realised that the problem also occurs when I login over ssh (without using tmux), and have edited the question accordingly.
– Rich
Jan 27 '11 at 9:56
4
ssh
is easy. Turn agent forwarding on. Easiest way to do that is runssh -A
instead ofssh
. Use an alias so you don't have to type it every time, or put it in your.SSH/config
.
– Mikel
Jan 27 '11 at 22:37
Cool, thanks. That worked for ssh. Any ideas how to fix it in tmux?
– Rich
Feb 1 '11 at 17:38
add a comment |
What does:
echo $SSH_AUTH_SOCK
echo $SSH_AGENT_PID
ssh-add -l
print?
Run it in your normal terminal, then run it inside your tmux
session. They should print the same thing.
I added the response to these commands to the question. I've also realised that the problem also occurs when I login over ssh (without using tmux), and have edited the question accordingly.
– Rich
Jan 27 '11 at 9:56
4
ssh
is easy. Turn agent forwarding on. Easiest way to do that is runssh -A
instead ofssh
. Use an alias so you don't have to type it every time, or put it in your.SSH/config
.
– Mikel
Jan 27 '11 at 22:37
Cool, thanks. That worked for ssh. Any ideas how to fix it in tmux?
– Rich
Feb 1 '11 at 17:38
add a comment |
What does:
echo $SSH_AUTH_SOCK
echo $SSH_AGENT_PID
ssh-add -l
print?
Run it in your normal terminal, then run it inside your tmux
session. They should print the same thing.
What does:
echo $SSH_AUTH_SOCK
echo $SSH_AGENT_PID
ssh-add -l
print?
Run it in your normal terminal, then run it inside your tmux
session. They should print the same thing.
answered Jan 25 '11 at 22:54
MikelMikel
7,54913434
7,54913434
I added the response to these commands to the question. I've also realised that the problem also occurs when I login over ssh (without using tmux), and have edited the question accordingly.
– Rich
Jan 27 '11 at 9:56
4
ssh
is easy. Turn agent forwarding on. Easiest way to do that is runssh -A
instead ofssh
. Use an alias so you don't have to type it every time, or put it in your.SSH/config
.
– Mikel
Jan 27 '11 at 22:37
Cool, thanks. That worked for ssh. Any ideas how to fix it in tmux?
– Rich
Feb 1 '11 at 17:38
add a comment |
I added the response to these commands to the question. I've also realised that the problem also occurs when I login over ssh (without using tmux), and have edited the question accordingly.
– Rich
Jan 27 '11 at 9:56
4
ssh
is easy. Turn agent forwarding on. Easiest way to do that is runssh -A
instead ofssh
. Use an alias so you don't have to type it every time, or put it in your.SSH/config
.
– Mikel
Jan 27 '11 at 22:37
Cool, thanks. That worked for ssh. Any ideas how to fix it in tmux?
– Rich
Feb 1 '11 at 17:38
I added the response to these commands to the question. I've also realised that the problem also occurs when I login over ssh (without using tmux), and have edited the question accordingly.
– Rich
Jan 27 '11 at 9:56
I added the response to these commands to the question. I've also realised that the problem also occurs when I login over ssh (without using tmux), and have edited the question accordingly.
– Rich
Jan 27 '11 at 9:56
4
4
ssh
is easy. Turn agent forwarding on. Easiest way to do that is run ssh -A
instead of ssh
. Use an alias so you don't have to type it every time, or put it in your .SSH/config
.– Mikel
Jan 27 '11 at 22:37
ssh
is easy. Turn agent forwarding on. Easiest way to do that is run ssh -A
instead of ssh
. Use an alias so you don't have to type it every time, or put it in your .SSH/config
.– Mikel
Jan 27 '11 at 22:37
Cool, thanks. That worked for ssh. Any ideas how to fix it in tmux?
– Rich
Feb 1 '11 at 17:38
Cool, thanks. That worked for ssh. Any ideas how to fix it in tmux?
– Rich
Feb 1 '11 at 17:38
add a comment |
There are many solutions, but the simplest one is found in Hans Ginzel's answer, dated 8 January 2016, to a related StackOverflow question dated 27 January 2014. Simply add the following to your shell ~/.profile
or similar:
alias ssh='eval $(tmux show-env -s | grep "^SSH_") && ssh'
There is no need to define multi-line functions or create new temporary files. If you don't want to alias ssh
, simply change it to fixssh
and remove && ssh
at the end, and run fixssh
whenever you're trying to run ssh
from inside a reattached tmux session.
The answer by Hans Ginzel suggests that a 'newer version' of tmux is required to run show-env -s
. This works for me in tmux 2.7, and on my reading of the changelog, -s
was added on 3 June 2008 just before the release of tmux 0.3. tmux 2.3 (29 September 2016) is in Debian stable.
New contributor
add a comment |
There are many solutions, but the simplest one is found in Hans Ginzel's answer, dated 8 January 2016, to a related StackOverflow question dated 27 January 2014. Simply add the following to your shell ~/.profile
or similar:
alias ssh='eval $(tmux show-env -s | grep "^SSH_") && ssh'
There is no need to define multi-line functions or create new temporary files. If you don't want to alias ssh
, simply change it to fixssh
and remove && ssh
at the end, and run fixssh
whenever you're trying to run ssh
from inside a reattached tmux session.
The answer by Hans Ginzel suggests that a 'newer version' of tmux is required to run show-env -s
. This works for me in tmux 2.7, and on my reading of the changelog, -s
was added on 3 June 2008 just before the release of tmux 0.3. tmux 2.3 (29 September 2016) is in Debian stable.
New contributor
add a comment |
There are many solutions, but the simplest one is found in Hans Ginzel's answer, dated 8 January 2016, to a related StackOverflow question dated 27 January 2014. Simply add the following to your shell ~/.profile
or similar:
alias ssh='eval $(tmux show-env -s | grep "^SSH_") && ssh'
There is no need to define multi-line functions or create new temporary files. If you don't want to alias ssh
, simply change it to fixssh
and remove && ssh
at the end, and run fixssh
whenever you're trying to run ssh
from inside a reattached tmux session.
The answer by Hans Ginzel suggests that a 'newer version' of tmux is required to run show-env -s
. This works for me in tmux 2.7, and on my reading of the changelog, -s
was added on 3 June 2008 just before the release of tmux 0.3. tmux 2.3 (29 September 2016) is in Debian stable.
New contributor
There are many solutions, but the simplest one is found in Hans Ginzel's answer, dated 8 January 2016, to a related StackOverflow question dated 27 January 2014. Simply add the following to your shell ~/.profile
or similar:
alias ssh='eval $(tmux show-env -s | grep "^SSH_") && ssh'
There is no need to define multi-line functions or create new temporary files. If you don't want to alias ssh
, simply change it to fixssh
and remove && ssh
at the end, and run fixssh
whenever you're trying to run ssh
from inside a reattached tmux session.
The answer by Hans Ginzel suggests that a 'newer version' of tmux is required to run show-env -s
. This works for me in tmux 2.7, and on my reading of the changelog, -s
was added on 3 June 2008 just before the release of tmux 0.3. tmux 2.3 (29 September 2016) is in Debian stable.
New contributor
New contributor
answered 21 hours ago
sjysjy
1012
1012
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f237822%2fhow-can-i-get-ssh-agent-working-over-ssh-and-in-tmux-on-os-x%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What about
typeset -p SSH_AUTH_SOCK
?– Mikel
Jan 27 '11 at 11:18
@Mikel
bash: typeset: SSH_AUTH_SOCK: not found
from within ssh/tmux. I'll try it locally tonight, if necessary.– Rich
Jan 27 '11 at 12:53
@Mikel I've added that command's output to the question.
– Rich
Jan 27 '11 at 20:33
AFAIK, question and answers are not OS X-specific. That's relevant to avoid some non-OS X-specific dups, namely superuser.com/q/334975/46794 and superuser.com/q/479796/46794.
– Blaisorblade
Sep 19 '13 at 8:33
@Blaisorblade I was under the impression my passphrase was stored in the OS X keychain (Although I can't remember now why I believed that to be the case). Is that incorrect?
– Rich
Sep 19 '13 at 8:52