No, this is not secure.
Let's call your machines local and remote. What you're doing right now is creating a tunnel for X11 from local to local, then running a VNC client over that tunnel and using it to connect to remote. This effectively does nothing, traffic between local and remote isn't going over the SSH tunnel.
Originally it sounded like you might be saying that you were SSHing from local to remote, running a VNC client on remote X11 forwarded to local, then using the VNC client to connect from remote to remote. This would be secure (as long as you trust the remote computer, X11 forwarding is somewhat vulnerable if remote is malicious; I'm not familiar enough with VNC to know if this is better or worse than using VNC directly) but it seems convoluted and unnecessary, and I would guess performance would suffer.
If you want to have VNC tunneled through an SSH connection the correct way to do this is to forward a port from local to remote using ssh -L
:
ssh -L [localhost port]:[host]:[host port] remote
This syntax can be a little confusing at first until you figure out what's happening on which machine. [host]
here is from the perspective of remote; what happens is that you're forwarding [localhost port]
to remote, then remote sends it to [host]:[host port]
, so what you actually want is:
ssh -L 5900:localhost:5900 remote
That way traffic is sent from local port 5900
to remote, then remote sends it to itself on port 5900
. Then you can use your VNC client on local to connect to local on port 5900
(if port 5900 is already used on local [localhost port]
can of course be changed to something else).
It's not relevant here because remote is forwarding to itself, but it's important to understand that once the traffic reaches remote it will be sent unencrypted. If you had a separate VNC host accessible from remote and used ssh -L 5900:vnchost:5900 remote
the traffic would be encrypted from local to remote, but not from remote to vnchost.
You didn't specify what protocol you were using, so this answer assumes VNC, but it would work equally well for other protocols simply by changing the port being forwarded. Also note that some desktop sharing protocols allow using TLS, which should make SSH forwarding unnecessary when implemented correctly.