Bug 2677 - Provide a way to set an environment variable from ssh_config
Summary: Provide a way to set an environment variable from ssh_config
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 7.4p1
Hardware: All All
: P5 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
: 2875 (view as bug list)
Depends on:
Blocks: V_7_8
  Show dependency treegraph
 
Reported: 2017-02-16 04:52 AEDT by Sascha Silbe
Modified: 2021-04-23 15:00 AEST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sascha Silbe 2017-02-16 04:52:02 AEDT
For various purposes it's useful to pass some more or less fixed string from the client to the server side. E.g. when forwarding sockets, the remote socket name needs to include some string unique to the local side (like the host name) to avoid collisions between connections from different hosts. Think gpg-agent forwarding or using emacsclient on the remote host to open the file (via TRAMP) on the local host.

This is currently possibly by using a wrapper script around ssh that sets some environment variable, but setting an environment variable directly in ssh_config would make things a lot smoother (no messing with PATH required). Being able to expand environment variables and use expansions like in the Match directive would be nice, but even a fixed string would go a long way.

E.g.:
=== Begin .ssh/config ===
Host *.localdomain
   SetEnv EMACS_SOCKET=/home/sascha/.emacs.d/server/server.%l
   SetEnv GPG_AGENT_INFO=/home/sascha/.gnupg/S.gpg-agent.%l:1:1
   
Host myserver.localdomain
   RemoteForward /home/sascha/.emacs.d/server/server.mydesktop:/tmp/emacs8193/server
   RemoteForward /home/sascha/.gnupg/S.gpg-agent.mydesktop:/home/sascha/.gnupg/S.gpg-agent
=== End .ssh/config ===

(As you can see, environment variables and Match-like expansions would be useful in RemoteForward as well, but that's a feature request for another day).
Comment 1 Damien Miller 2018-06-09 13:20:23 AEST
ssh_config (and sshd_config) now have a SetEnv option that does just this.
Comment 2 Damien Miller 2018-06-09 13:20:42 AEST
*** Bug 2875 has been marked as a duplicate of this bug. ***
Comment 3 Sascha Silbe 2018-07-07 19:56:53 AEST
Thanks! Does the current implementation support keyword expansion? The man page doesn't say and I couldn't see any expansion happening in the code (but I may have overlooked it).

I'm using the same SSH config on multiple hosts so being able to expand the local hostname (%l, like in my example above) would be really useful.
Comment 4 Damien Miller 2021-04-23 15:00:24 AEST
closing resolved bugs as of 8.6p1 release