SSH - Advanced Terminal Tricks - Part 1 - Geek Beacon


#1

Let's learn about X11 forwarding... this will allow me to run a graphical program from a remote server and see it locally as if I was sitting right there.

ssh -X nixie@bacon.geekbeacon.org (Note the -X that's the really important part here)

Now, let's validate that the server is configured correctly. The SSH server is configured by a fun little file called sshd_config that usually lives in your /etc/ssh directory.

What we need to confirm is that the option X11Forwarding is set to a value of yes, otherwise flip it from no to yes and restart the server using your favorite service manager. For Ubuntu you can restart in either of the following ways:

  • sudo service ssh restart
  • sudo /etc/init.d/ssh restart

Once ssh has been restarted you can run any application that's installed on your server whether it has a GUI or not. Sadly this won't work for any of your favorite games. I chose gnome-todo as an example but really anything you can think of that you wanted to access will work. Firefox? Chrome? Wunderlist? What's your favorite program you can't live without that you absolutely must have but isn't available everywhere you're at. Do you need access to all that data you have stored on your NAS but don't want to transfer gigs and gigs of data? It doesn't matter, if you run your program with SSH X11 forwarding all the data doesn't need to be transferred and it has the benefits of being secure through SSH.

X11 forwarding is one of the easiest ways of access a GUI environment remotely, though it does have the draw back of being somewhat slower especially if your app wants to redraw the screen. Don't worry, we'll talk about other more fun ways of bring the GUI over the secure wires next time as we look into SSH Tunnels and VNC.

What is your favorite SSH tips and tweaks? Llama wants to know! :D :D :D


This is a companion discussion topic for the original entry at https://www.geekbeacon.org/news/ssh-advanced-terminal-tricks-part-1/

#2

SSH jump host. It allows you to specify multiple hosts to jump from one host to another. Good for example if you have a jump box you must access to be able to access other hosts on a network.

Used like follows.

ssh -J host1 host2

Gentoo has a good guide on using it.

https://wiki.gentoo.org/wiki/SSH_jump_host


#3

Thanks @Eden that’s really cool. I’ve done that indirectly though I wonder if you can combine that with tunneling.

That could be really fun/powerful.


#4

#5

#6

#7

#8

I had to do one another step. On server side when I have setup ssh configurations, I needed to install xauth app.

“sudo apt install xauth”

Then I could run applications. I was surprised i got it working. :smiley:


#9

You definitely do need an X server of some kind running on the ‘server’ side. I rarely have X running but this is great when I just have ssh enabled for my desktop home computer. I can access my files, run apps and so on if need be.

Someone also mentioned this in the youtube comments, but -Y also works for X forwarding.

At times, I also had to do xhost + to allow x-forwarding, it depends on how your system is setup, but this tutorial should cover the 90% use case and at least I tested it on Ubuntu with the directions nixie posted.


#10

X forwarding over SSH is quite slow - though I do use it sometimes. If you want it to be less annoying, you can use NX - though I never did that “on its own”. I do use x2go quite a bit, which uses NX and the SSH mechanics - but you need to have an x2go-Server on the target machine, and it can be a bit unwieldy to install an use. But it is in many ways an easier alternative to VNC.

So, if anybody has a nice documentation on how to use NX with SSH I would be interested.


#11

@Plentyn this looks like a decent guide though I’ve never experiment with it. It seems it has several clients for all the major OSes. Server is probably limited to Linux.


#12

Alternatively The x2go-Wiki page will do the trick quite nicely.

I was more asking about a link to use NX without x2go - x2goserver is neat, if you want to set up a machine around it, but it is a bit unwieldy for casual use. x2goclient is cool is you want to have a remote desktop - but the option to just use (multiple) windows remotely like with pure ssh is not as easy to have.