2

I use Bash for my terminal on Debian. In my .bashrc, I've defined an environmental variable like so:

SSH_VAULT_VM="ssh-vault"

if [ "$SSH_VAULT_VM" != "" ]; then
    export SSH_AUTH_SOCK=~user/.SSH_AGENT_$SSH_VAULT_VM
fi

This is to facilitate separating my SSH private/public keys on my bare metal host OS (Qubes OS) as described in this repo. The way split SSH works in Qubes OS is by hosting the private key in a VM, and the public key in another VM (from which I'm running Emacs). Whenever I use SSH then, a dialog box pop-up appears to confirm accessing the private key.

When I open Emacs from a Bash terminal, the SSH_AUTH_SOCK variable is properly defined (as observed in the initial-environment variable), and attempts to use the SSH key (e.g., in the magit package) succeed with the pop-up confirmation box. However, when I open the Emacs GUI (using X?), the SSH_AUTH_SOCK variable is incorrect (instead set to something like: /tmp/ssh-[some random name]/agent.[3 digit number]) and attempts to use the SSH key fail.

How can I make Emacs use my .bashrc settings such that this split SSH feature will work? I'd be happy to either correct some config to make Emacs load this variable correctly, or overwrite it with the correct value in my .emacs.d file. I've tried including something like: (setenv "SSH_AUTH_SOCK" "/home/user/.SSH_AGENT_ssh-vault") in my Emacs config, but that doesn't seem to work.

2
  • Try putting the definition in your $HOME/.profile. It might or might not work (depending on how your desktop environment gets initialized) but it's much more likely to happen with $HOME/.profile.
    – NickD
    Sep 6, 2020 at 18:44
  • 1
    Emacs can only inherit the environment which was present when it ran. If you are not running your GUI instance from a bash shell, then your .bashrc will obviously have no effect.
    – phils
    Sep 6, 2020 at 22:31

1 Answer 1

1

I'd say you want it in the .profile instead .bashrc. It works from emacs terminal because it's associated with a terminal, thus reads the file first.

Read Bash startup files.

edit: I was assuming that we were talking about user configuration files, something that later I've realized it wasn't that clear. Also, you can use .xsessionrc to make those variables available on X sessions.

7
  • The reason I'm including it in my .bashrc is to implement split SSH as per this repo. I've tried moving the variable definition to .profile as you recommend, instead of .bashrc, but this breaks the functionality of split SSH, even though initial-environment is now correct. Know of another solution?
    – ch-pub
    Sep 6, 2020 at 16:43
  • please include the repo reference you're trying to make it work and the intended purpose in the question, comments are volatile.
    – Muihlinn
    Sep 6, 2020 at 16:59
  • Updated question to describe split SSH objective
    – ch-pub
    Sep 6, 2020 at 17:14
  • 1
    try putting into .bash_login instead, I don't know it it'll work as I have zero experience with Qubes OS and how things are shared among VMs. Anyway isn't an emacs issue, it's just your environment variable isn't set for the X session where you want to access it.
    – Muihlinn
    Sep 6, 2020 at 17:47
  • Typical init scripts (e.g. /etc/X11/xinit/xinitrc-common/ on my Fedora 31 system) only look at $HOME/.profile - you can always cheat and source your $HOME/.bashrc from your $HOME/.profile: it's icky and I would try to avoid it, but desperate times might call for desperate measures.
    – NickD
    Sep 6, 2020 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.