I have my desktop in the office. When X starts, ssh-agent starts automatically. I have to add my SSH key once, at the beginning, and then I can use ssh without having to enter my password each time.However, when I connect to my desktop via SSH (i.e. from home) the ssh-agent is not accessible and I have to provide my key every time. Also, even if I start a new instance of ssh-agent, I still cannot connect to it.Is there a way to use ssh-agent on a remote system (to which I am connected via ssh?
using ssh-agent
ssh;openssh;ssh agent
You can use agent forwarding: make sure to include ForwardAgent yes in your client-side configuration (~/.ssh/config), or use the -A command line option. (This feature can be disabled on the server side (AllowAgentForwarding in sshd_config), but this is only useful for restricted accounts that cannot run arbitrary shell commands.) This way, all the keys from your local machine are available in the remote session. Note that enabling agent forwarding on the client side has security implications: it gives the administrator of the remote machine access to your keys (for example, if you are at A and have a key for B and a key for C, and enable agent forwarding in your connection to B, then this lets B access your keys and hence log into C).If you want to make the agent from your X session on the office machine available in the SSH sessions from home, then you need to set the SSH_AUTH_SOCK environment variable to point to the same file as in the X session. It's easy enough to do manually:export SSH_AUTH_SOCK=/tmp/ssh-XXXXXXXXXXXX/agent.12345where XXXXXXXXXXXX is a random string and 12345 is the PID of the agent process. You can automate this easily if there is a single running agent (find /tmp -maxdepth 1 -user $USER -name 'ssh-*') but detecting which agent you want if there are several is more complicated.You can extract the value of SSH_AUTH_SOCK from a running process. For example, on Linux, if your window manager is Metacity (the default Gnome window manager):env=$(grep -z '^SSH_AUTH_SOCK=' /proc/$(pidof -s metacity)/environ')if [ -n $env ]; then export $env; fiAlternatively, you can configure your office machine to use a single SSH agent. If the agent is started automatically when you log in, then in most distributions, it won't be started if there is already a variable called SSH_AUTH_SOCK in the environment. So add a definition of SSH_AUTH_SOCK to your ~/.profile or ~/.pam_environment, and manually start ssh-agent if it isn't already started in .profile:export SSH_AUTH_SOCK=~/.ssh/$HOSTNAME.agentif [ -z $(pgrep -U $USER ssh-agent) ]; then  ssh-agent >/dev/nullfi