You are not logged in.

#1 2022-09-19 15:58:30

LyonN
Member
From: Argentina
Registered: 2022-09-19
Posts: 5

[SOLVED] ssh-agent autostart

Hi, i know there is a lot of posts about ssh-agent, but i couldn't find my issue.
I added the start lines to the bashrc file following the arch wiki, but it didn't work. I figured out that something is starting the ssh-agent when the X start but i cant find what is it.
Do you have any idea what it could be?

I'm using ArchLinux + I3 + Lightdm

this is the bashrc code for starting the agent.

if ! pgrep -u "$USER" ssh-agent > /dev/null; then
    ssh-agent -t 1h > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
if [[ ! -f "$SSH_AUTH_SOCK" ]]; then
    source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
fi

if i manually kill the agent before opening terminal, this works perfect.

thanks a lot!

Last edited by LyonN (2022-09-20 14:59:12)

Offline

#2 2022-09-19 20:02:14

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,485

Re: [SOLVED] ssh-agent autostart

Do you have any idea what it could be?

Did you check the process list? (ie. what's the parent process of the running ssh-agent ?)
Did you maybe enable a systemd user service and forgot about that?
Does lightdm start the session using bash and source the bashrc (ie. your bashrc runs the original process)?

Offline

#3 2022-09-19 22:47:24

LyonN
Member
From: Argentina
Registered: 2022-09-19
Posts: 5

Re: [SOLVED] ssh-agent autostart

Hi, thanks for the answer.
For testing i disabled lightdm and do a startx URxvt. So its not a lightdm or i3 config problem.
when i do ps aux | grep ssh i got this:

gabriel      779  0.0  0.0   5836     4 ?        Ss   17:29   0:00 /usr/bin/ssh-agent -s

i figured out not only ssh-agent is starting, but also ~/.ssh/id_rsa is automatically added.

when i do systemctl --user list-units --type=service i get

at-spi-dbus-bus.service             loaded active running Accessibility se>
dbus.service                        loaded active running D-Bus User Messa>
dconf.service                       loaded active running User preferences>
gvfs-daemon.service                 loaded active running Virtual filesyst>
gvfs-metadata.service               loaded active running Virtual filesyst>
gvfs-udisks2-volume-monitor.service loaded active running Virtual filesyst>
obex.service                        loaded active running Bluetooth OBEX s>
pulseaudio.service                  loaded active running Sound Service

and with systemctl list-units --type=service

alsa-restore.service                                                      >
  bluetooth.service                                                         >
  dbus.service                                                              >
  kmod-static-nodes.service                                                 >
  lightdm.service                                                           >
  lvm2-monitor.service                                                      >
  NetworkManager.service                                                    >
  polkit.service                                                            >
  rtkit-daemon.service                                                      >
  systemd-binfmt.service                                                    >
  systemd-fsck@dev-disk-by\x2duuid-724713ab\x2d079d\x2d488d\x2d996f\x2d31988>
  systemd-fsck@dev-disk-by\x2duuid-77D2\x2d6E13.service                     >
  systemd-journal-flush.service                                             >
  systemd-journald.service                                                  >
  systemd-logind.service                                                    >
  systemd-machined.service                                                  >
  systemd-modules-load.service                                              >
  systemd-random-seed.service                                               >
  systemd-remount-fs.service                                                >
  systemd-sysctl.service                                                    >
  systemd-tmpfiles-setup-dev.service                                        >
  systemd-tmpfiles-setup.service                                            >
  systemd-udev-trigger.service                                              >
  systemd-udevd.service                                                     >
  systemd-update-utmp.service                                               >
  systemd-user-sessions.service                                             >
  udisks2.service                                                           >
  user-runtime-dir@1000.service                                             >
  user@1000.service                                                         >
  virtlogd.service

i'm crazy with this. Something is starting the agent, but i cant find where!.
Thanks a lot!

EDIT:
the parent of the process is /sbin/init

seth wrote:

Do you have any idea what it could be?

Did you check the process list? (ie. what's the parent process of the running ssh-agent ?)
Did you maybe enable a systemd user service and forgot about that?
Does lightdm start the session using bash and source the bashrc (ie. your bashrc runs the original process)?

Last edited by LyonN (2022-09-19 23:11:28)

Offline

#4 2022-09-20 06:49:03

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,485

Re: [SOLVED] ssh-agent autostart

"startx URxvt" will have executed your bashrc before?
Try to not have this in your bashrc, is the pre-emptive ssh-agent process still there?

(ssh-agent forks and reparents itself to PID 1, so no surprise or indication from there)

Offline

#5 2022-09-20 12:50:25

LyonN
Member
From: Argentina
Registered: 2022-09-19
Posts: 5

Re: [SOLVED] ssh-agent autostart

You are right, the startx /usr/bin/urxvt with a clean .bashrc file don't start the agent, that was my bad.
i think that means it should be something that i3 is starting.

seth wrote:

"startx URxvt" will have executed your bashrc before?
Try to not have this in your bashrc, is the pre-emptive ssh-agent process still there?

(ssh-agent forks and reparents itself to PID 1, so no surprise or indication from there)

Offline

#6 2022-09-20 14:05:29

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,485

Re: [SOLVED] ssh-agent autostart

i think that means it should be something that i3 is starting.

I think it's your bashrc that it's starting this?
Do you get the undesired agent when you start i3 w/ lightdm but w/o the segment in your bashrc?

Offline

#7 2022-09-20 14:19:20

LyonN
Member
From: Argentina
Registered: 2022-09-19
Posts: 5

Re: [SOLVED] ssh-agent autostart

Yes, this is my actual bashrc:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# Prompt config
PS1='\[\e[0;1;2;38;5;219m\][\[\e[0;1;2;38;5;219m\]\w\[\e[0;1;2;38;5;219m\]] \[\e[0;1;2;38;5;39m\]\u \[\e[0;1;2;38;5;39m\]> \[\e[0m\]'

# Aliases
alias sudo='sudo '
alias vim='nvim'
alias bashrc='nvim ~/.bashrc'
alias i3config='nvim ~/.config/i3/config'
alias ls='ls --color=auto'
alias vimconfig='nvim ~/.config/nvim/init.vim'
alias rm='trash'

and when i ps aux | grep ssh

gabriel      784  0.0  0.0   5836   440 ?        Ss   09:38   0:00 /usr/bin/ssh-agent -s

using or not the lightdm, when i start the X the agent is started. If i kill the agent, and start X again, the agent is started again.

i'm not using the segment in bashrc because the agent is actually started. But the problem is that SSH_AUTH_SOCK and SSH_AGENT_PID are not set, that's why i'm trying to solve this.

EDIT:
I tested executing i3 with a default .config/i3/config file and the agent is not executing.

Something in my config is doing the job.

Ok, new EDIT:
I found the problem. The lxsession is executing the ssh-agent.
thank you very much for your help, i will mark the post as solved.

seth wrote:

i think that means it should be something that i3 is starting.

I think it's your bashrc that it's starting this?
Do you get the undesired agent when you start i3 w/ lightdm but w/o the segment in your bashrc?

Last edited by LyonN (2022-09-20 14:58:46)

Offline

Board footer

Powered by FluxBB