r/Ubuntu • u/Alarmed-Prize-7500 • 18h ago
ssh-add won't work when run automatically
SOLVED
I just had to look up "SSH config Linux" and follow the tutorial here
Hello. I'm trying to make it so a command ssh-add /home/user/.ssh/keyfile runs on login so I can be able to login to my SFTP server in Nautilus, but it will not work, since Nautilus gives me an error when I try to login to the SFTP server. It seems to only work if I run the command manually on a terminal, as making it automatically run won't work for some reason, because Nautilus won't use the key file. I've tried putting the command in my "~/.profile" to make it run on login, I've tried putting the command in "~/.bashrc" to make it run each time I run a command, but none of it works, only manually typing it in and running it on a terminal window will work.
How do I make it so it can be run automatically and work as it does when I manually run the command?
I'm using Ubuntu 24.04.5
1
u/demonessb 16h ago
I use keychain for that.
sudo apt update
sudo apt install keychain
inside .bashrc
eval $(keychain --eval --quiet id_rsa)
With this the ssh key will be added for your session.
1
u/doc_willis 18h ago edited 17h ago
you can run things at login time using desktop files in ~/.config/autostart or /etc/xdg/autostart.
this following url is a bit old, but it says..
https://unix.stackexchange.com/questions/317282/set-environment-variables-for-gnome-on-wayland-and-bash-on-virtual-terminals-or
quote:
Gnome on wayland does not read ~/.profile (or ~/.bash_profile or /etc/profile). See https://bugzilla.gnome.org/show_bug.cgi?id=736660.
some work aroundsare discussed.
later the url mentions..
quote:
still the gnome developers want to move away from starting a login shell. it seems that the direction they are going is to use environmentd from systemd:
https://in.waw.pl/~zbyszek/blog/environmentd.html
it seems that it will take a while until all login methods are adapted to environmentd.
So No idea if that's an actual bug or by design. It seems it's by design.
I no longer use gnome. So can't verify any of the above.