SSH 代理不会在登录时启动

SSH 代理不会在登录时启动

我遇到了一个问题,即 ssh-agent 不会在登录时自动启动。我尝试编写服务、配置 systemd 自动启动脚本以及许多其他操作。

我注意到的另一件事是,即使我运行eval $(ssh-agent -s),代理也只能在我重新启动终端之前工作。关闭并再次打开终端,然后运行ssh-add -l会出现可怕的Could not open a connection to your authentication agent.消息。

在一些指导下,我编写的服务如下所示:

[Unit]
Description=SSH agent (ssh-agent)

[Service]
Type=simple
Environment="SSH_AUTH_SOCK=%t/ssh-agent.socket"
Environment="DISPLAY=:0"
ExecStart=ssh-agent -D -a $SSH_AUTH_SOCK
ExecStop=kill -15 $MAINPID

[Install]
WantedBy=default.target

但是,尽管启动和运行成功,它还是不起作用。输出如下systemctl

>> systemctl --user status ssh-agent
● ssh-agent.service - SSH agent (ssh-agent)
     Loaded: loaded (/home/david/.config/systemd/user/ssh-agent.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-01-30 20:08:14 GMT; 9min ago
    Process: 10959 ExecStartPost=/bin/sleep 3 (code=exited, status=0/SUCCESS)
   Main PID: 10958 (ssh-agent)
      Tasks: 1 (limit: 18864)
     Memory: 840.0K
        CPU: 8ms
     CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/ssh-agent.service
             └─10958 ssh-agent -D -a /run/user/1000/ssh-agent.socket

Jan 30 20:08:11 pleb-box systemd[839]: Starting SSH agent (ssh-agent)...
Jan 30 20:08:11 pleb-box ssh-agent[10958]: SSH_AUTH_SOCK=/run/user/1000/ssh-agent.socket; export SSH_AUTH_SOCK;
Jan 30 20:08:11 pleb-box ssh-agent[10958]: echo Agent pid 10958;
Jan 30 20:08:14 pleb-box systemd[839]: Started SSH agent (ssh-agent).

>> echo $SSH_AGENT_PID


>> echo $SSH_AUTH_SOCK


>> ssh-add -l
Could not open a connection to your authentication agent.

如您所见,它甚至没有导出两个环境变量,尽管这是第二行日志。尝试导出echo它们,返回空值。我使用 zsh,但这也会发生在 bash 上。

以下是我的一些系统信息:

>> uname -a
Linux pleb-box 5.15.89-1-MANJARO #1 SMP PREEMPT Wed Jan 18 20:37:11 UTC 2023 x86_64 GNU/Linux

>> zsh --version
zsh 5.9 (x86_64-pc-linux-gnu)

>> konsole --version
konsole 22.12.1

>> systemctl --version
systemd 252 (252.4-2-manjaro)
+PAM +AUDIT -SELINUX -APPARMOR -IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT -QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD +BPF_FRAMEWORK +XKBCOMMON +UTMP -SYSVINIT default-hierarchy=unified

>> ssh -v localhost
OpenSSH_9.1p1, OpenSSL 3.0.7 1 Nov 2022
...

任何帮助将不胜感激。

相关内容