0

I am running a CentOS 7 machine that only allows ssh access. On that machine I'm running a number of QEMU virtual machines, each with its display on a different VNC port. To access a machine I'm asking people to ssh to the machine and forward the port of the desired VNC server, for example, if one of the servers is on :25 they might run

ssh -L 5901:localhost:5925 user@host

then on their local machine open vncviewer to localhost:1

Since these VMs are going to be shared among many users, is there a way I can tell, as the administrator of the box, who has port forwarding setup to each VM (or any other arbitrary port for that matter)?

I can see my own by doing ~# but is there an easy way to see those for the other users?

The only thing I can think of right now is to do something like netststat -panl | awk '$5 ~ /5925/ {print $7 $8}' and repeat for each port of interest. Is there anything more "proper" or succinct?

0

While I'm still hoping that there is a way to just, say, query sshd for the information, I have come up with another work around that will tell me who has port forwarding opened to which ports on localhost:

lsof -i -n | awk '/sshd.*->127.0.0.1:/ {n=split($9,a,":"); print $3 " " a[n];}'

which will print, for example

erenouf 5925
erenouf 5926

but only if I have already tried to use those connections, not merely requested that ssh do the forwarding.

This also requires me to know the destination IP, which I do for this scenario (so far, until we add a second machine), so it still isn't completely satisfying yet.

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.