Ssh

SSH:來自沒有外殼的使用者的 ProxyJump

  • February 20, 2022

我有一個系統syncoid使用者

$ cat /etc/passwd
syncoid:x:993:990::/var/lib/syncoid:/run/current-system/sw/bin/nologin

使用以下 ssh 配置:

$ cat /var/lib/syncoid/.ssh/config
Host eve
 User other
 HostName 192.168.10.1
 ProxyJump jumphost
 IdentityFile /var/lib/syncoid/.ssh/eve-syncoid
Host jumphost
 ForwardAgent yes
 User me
 HostName 192.168.1.1
 IdentityFile /var/lib/syncoid/.ssh/eve-syncoid

我可以使用sudo -u syncoid ssh jumphost. 但是,與伺服器的連接evesudo -u syncoid ssh -vvv eve導致

OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021
debug1: Reading configuration data /var/lib/syncoid/.ssh/config
debug1: /var/lib/syncoid/.ssh/config line 1: Applying options for eve
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 5: Applying options for *
debug2: resolve_canonicalize: hostname 192.168.10.1 is address
debug1: Setting implicit ProxyCommand from ProxyJump: ssh -vvv -W '[%h]:%p' jumphost
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/var/lib/syncoid/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/var/lib/syncoid/.ssh/known_hosts2'
debug1: Executing proxy command: exec ssh -vvv -W '[192.168.10.1]:22' jumphost
debug1: identity file /var/lib/syncoid/.ssh/eve-syncoid type 0
debug1: identity file /var/lib/syncoid/.ssh/eve-syncoid-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.8
debug1: kex_exchange_identification: banner line 0: This account is currently not available.
kex_exchange_identification: Connection closed by remote host
Connection closed by UNKNOWN port 65535

我是否需要使用 shell 的普通使用者來執行 ProxyJump?

編輯:

  • eve在沒有 ProxyJump over VPN的情況下登錄可以正常工作,因此密鑰和配置的一切都是正確的。
  • 我創建了一個具有相同鍵/配置的普通使用者,並且 ProxyJump 在那里工作。

這實際上不是 ProxyJump 問題 - 該服務是具有有限 RootDirectory 的強化 systemd 服務,因此它無法訪問私有 ssh 密鑰。

必須將帶有私鑰的文件夾添加到此 github 評論BindReadonlyPaths的後面

config.services.syncoid.service.serviceConfig.BindReadOnlyPaths = [ 
 "/var/lib/syncoid/.ssh" 
];

在進一步評論之後,這將在未來通過這個拉取請求來解決。

這實際上是 NixOS 中的 syncoid 服務定義過於嚴格的問題。我不得不覆蓋

systemd.services."syncoid-rpool-user-home" = {
   serviceConfig = {
     ProtectHome = lib.mkForce false;
     StateDirectory = lib.mkForce "";
     RootDirectory = lib.mkForce "";
   };
};

引用自:https://unix.stackexchange.com/questions/690494