大网数据广告活动
服务器运维问答

chroot, gpg-agent, and Ubuntu 18.04

· 52CE 我爱测

For SFTP access to my server, I have created a sftp user that is limited to a working directory by chroot . Match User sftp-user AuthorizedKeysFile /home/sftp-user/.ssh/authorized_keys ChrootDirectory /var/www/domain ForceCommand…

问题原文

原帖链接 · BurninLeo · CC BY-SA 4.0

For SFTP access to my server, I have created a sftp user that is limited to a working directory by chroot.

Match User sftp-user
    AuthorizedKeysFile /home/sftp-user/.ssh/authorized_keys
    ChrootDirectory /var/www/domain
    ForceCommand internal-sftp
    AllowTcpForwarding no
    X11Forwarding no

And this entry in /etc/passwd

sftp-user:x:1003:1003::/html:/usr/sbin/nologin

There were some issues with the key file, but setting an absolute path for that solved the issue. The SFTP login worked fine until - I do not exactly know - the nagios server monitoring was installed on the server (a VPS) and/or updates have been run, and the system has been rebooted.

Now, connection fails and the syslog shows this error:

systemd[7590]: gpgconf: running /usr/bin/gpg-agent failed (exitcode=2): General error
systemd[7590]: gpgconf: fatal error (exit status 1)

This error occurs no matter if the login is done via key file or password. So I have tried following the question gpg-agent says agent exists, but gpg says agent doesn't exist? to narrow down the problem.

$ gpg-agent --version
gpg-agent (GnuPG) 2.2.4
libgcrypt 1.8.1

When I started gpg-agent as user (not the sftp user), it creates a file in the home directory on the first run:

$ gpg -d demo-file.asc
gpg: keybox '/home/username/.gnupg/pubring.kbx' created

When I disable the chroot in /etc/ssh/sshd_config, the login works properly. So I assume, that some access fails in the chroot session. As the sftp user is not allowed to use a shell, I did not bind any directories into the sftp-user's home directory.

社区高分解答

原帖链接 · BurninLeo · CC BY-SA 4.0

It actually was the .gnupg directory that could not be created. The home directory specified in /etc/passwd (/html) is relative during the SFTP session, but understood as absolute path during the login. Therefore...

  • Creating a folder .gnupg in chroot+home = /var/www/domain/html did not (!) help.
  • Creating a folder /html/.gnupg (.gnupg owned by sftp-user) removed the error message from /syslog.

To take care of further problems (of course, it did not work immediately), I started another sshd daemon in verbose mode and connected to this port .... but that would lead off topic here.

sudo /usr/sbin/sshd -d -p 3321

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-02-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。