I have a special user on my server, let's call it foo. I use it only for port forwarding.
The user's .ssh/authorized_keys2 is set up to prevent login and to open only a specific port:
no-pty,no-X11-forwarding,permitopen="localhost:4000",\
command="/bin/echo do-not-send-commands" ssh-rsa <long public key> bar@foobar
Additionally, the foo has its shell set to /bin/false in /etc/passwd.
I can't log onto the machine (that's what I want):
$ ssh foo@remote
PTY allocation request failed on channel 0
Connection to remote closed.
But I can open ports. Interestingly, I can open port 4000, but also other unprivileged ports:
$ ssh -N -R 4001:localhost:22 foo@remote
> # connection established
On remote with user bar, I can connect:
$ ssh -p4001 bar@localhost
bar@localhost's password:
Last login: Fri Sep 26 09:23:45 2014 from localhost.localdomain
...
Why can user
fooopen port 4001, when I limited it topermitopen="localhost:4000"?