SSH – How to Limit Remote Port Forwarding

port-forwardingSecurityssh

I need to limit which ports can be remotely 'ssh -R' forwarded by an user.

I know about permitopen option on authorized_keys, but as it says on man page it only limits local 'ssh -L' port forwarding

As discussed here a user would get the same with netcat or similar, but in this case user has no shell access

I also found this thread that talks about using selinux or LD_PRELOAD, but I never configured selinux before and can't find info on how to do that with LD_PRELOAD.

maybe someone have made a patch for openssh to implement that?

EDIT:
I've found this bug report so I guess it's not yet implemented

Best Answer

This has been implemented in OpenSSH 7.8p1, which was released 2018-08-24. Quote from the release notes:

add a PermitListen directive to sshd_config(5) and a corresponding permitlisten= authorized_keys option that control which listen addresses and port numbers may be used by remote forwarding (ssh -R ...).

Related Question