At first, I'd like to note that I am aware that there are a lot of other questions regarding SSH agent forwarding. The people there wanted to know how to make agent forwarding work or how to configure it securely. But I have the opposite problem: It seems that I can't reliably disable it. So here we go:
I am running a Debian bullseye system, up to date at the time of writing, basically vanilla. On that system, a SSH daemon is running, with the following configuration in
AcceptEnv LANG LC_* AllowAgentForwarding no AllowTcpForwarding no AllowStreamLocalForwarding no ChallengeResponseAuthentication no Ciphers [email protected],[email protected] Compression no DebianBanner no HostKeyAlgorithms rsa-sha2-512,ssh-ed25519 KbdInteractiveAuthentication no KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group-exchange-sha256 ListenAddress aaa.bbb.ccc.ddd LoginGraceTime 20 MACs [email protected],[email protected] PasswordAuthentication no PermitUserRC no Protocol 2 # The first of the following version is the right one. # However, for brain-dead WinSCP, we need the second version. #PubkeyAcceptedKeyTypes rsa-sha2-512,rsa-sha2-256,ssh-ed25519 PubkeyAcceptedKeyTypes rsa-sha2-512,rsa-sha2-256,ssh-ed25519,ssh-rsa RekeyLimit 100M 20m Subsystem sftp /usr/lib/openssh/sftp-server Match user copyremote ChrootDirectory /backup ForceCommand /usr/lib/openssh/sftp-server
This is the complete configuration file; nothing has been removed or obfuscated except the IP address it listens on. Furthermore, there are no other places that contain additional configuration snippets for the SSH daemon.
Basically, that configuration tries to turn off every feature I don't need, for example the agent forwarding feature (note: In that configuration file, I didn't add the lines for most of the features that are off by default (according to the manual)). We also see that the authentication is based on public keys exclusively.
The other day I was investigating a problem with the user
copyremote and the sftp subsystem and therefore gave
-v as parameter to
sftp on a client machine. That lead to the following output (showing only relevant portions):
root@morn ~/scripts # sftp -v -i ~/.ssh/id_rsa_backup_user [email protected]:/backup/achilles.bsdtar.gz . OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n 15 Mar 2022 [...] debug1: Remote: /home/usr/copyremote/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding debug1: Remote: /home/usr/copyremote/.ssh/authorized_keys:1: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding [...]
Now that's frightening. I thought I had turned off agent forwarding globally in the system-wide configuration file on the server. However, as I understand that output, it offers it.
Could anybody please explain how I can turn off agent forwarding (and further features that I don't want the server to offer) globally?
Those features can be explicitly disabled in the
authorized_keys files, but that would be very error prone and a lot of work if there are multiple users and each of them accepts multiple public keys, so I'd really prefer being able to turn it off at one place.
This is the
authorized_keys file of the user
copyremote on the server:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDs6ku+LXaUBs....JFchhaoQ== me@client
There is nothing special in there. Notably, agent forwarding is not allowed explicitly. Why does it not apply the setting from the system-wide configuration then?
P.S. I am aware that SSH / SFTP chroot does not provide the security we would expect from it. I have implemented further measures on the server that mitigate that problem, so it doesn't need to be discussed here :-)