2

I'm trying to restrict an SSH-tunnel user.

# sudo cat /home/user/.ssh/config
Banner none
ChrootDirectory /home/%u
PasswordAuthentication no
AllowTcpForwarding yes
X11Forwarding no
AllowAgentForwarding no
ForceCommand /bin/false

However, none of these seem to have any effect.

When I prepend /home/user/.ssh/authorized_keys with no-pty,no-agent-forwarding,no-X11-forwarding,command="/bin/false" it works, but I'd like to also include these directives into permanent configuration.

Is it possible to restrict a user this way without updating /etc/ssh/sshd_config?

UPDATE I know about Match User and Match Group; the point is to have this in a user-specific config.

3 Answers 3

1

Regarding /home/user/.ssh/config, that's purely for ssh client itself, used on the machine initiating the ssh connection. So not useful here.

Question has been updated saying you've discounted the prospect of adding Match User or Match Group entries into /etc/ssh/sshd_config, because you want a user-specific config.

If you want certain users to be chrooted into their home directory, you could leverage group membership instead, such as this, specifically using Match Group and ChrootDirectory %h.

Match Group jailed
  Banner none
  ChrootDirectory %h
  PasswordAuthentication no
  AllowTcpForwarding yes
  X11Forwarding no
  AllowAgentForwarding no
  ForceCommand /bin/false
3
  • Thanks, I've already seen this, but I'd like to avoid editing /etc/sshd_config, if possible.
    – mehov
    Aug 24, 2018 at 13:47
  • 1
    Can you please add the "only used by the ssh client, on the machine initiating the ssh connection, so ignored by sshd" part to your answer? (Because it actually answers.) If I attempt to do that, it'll probably be rejected by the mods
    – mehov
    Aug 24, 2018 at 18:51
  • As for the Include - I thought about it, and even tried it, unfortunately it doesn't work. I'll post some more info as an answer.
    – mehov
    Aug 24, 2018 at 18:52
1
# sudo cat /home/user/.ssh/config

UPDATE I know about Match User and Match Group; the point is to have this in a user-specific config.

Something like ForceCommand works to limit what the user can do. That doesn't work well in a configuration file placed in the user's home directory, since they would almost certainly be able to change the configuration, or at least to make it inaccessible (e.g. mv ~/.ssh ~/.ssh_disabled).

Of course, .ssh/config is also the configuration for the SSH client, that is, it modifies what happens when you make an SSH connection out of that system. Restricting a user must necessarily happen on the server, and sshd_config is the only place where ForceCommand is documented to exist. Also, as you say, Include only exists for the client configuration, so your options are a) put the ForceCommand in the sshd_config of the machine with a suitable Match command, or b) don't put the ForceCommand anywhere.

Of course, you could put the SSH server's configuration together from distinct files with some external system, the simplest of which would be something like cat /etc/ssh/sshd_config.d/*.conf > /etc/ssh/sshd_config.

0

First thing that comes to mind: use the Include directive.

However, it only works inside the /etc/ssh/ssh_config (ssh as a client), and when called in /etc/ssh/sshd_config (ssh as a server), throws a "Bad configuration option: include" error - apparently, it was only implemented for the client side

Problem is: the directives I need (such as ForceCommand) are for the server side, therefore ignored when added to ssh_config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.