Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

Monday, March 7, 2011

Linux and SSH

Sometime ago I built myself a media server. This is a Linux box running Xubuntu and setup to stream media to the XBox 360, the Western Digital Media Player and connected to the audio in on the stereo. I searched and searched for a good howto so I could setup VNC on my server so I could control the media player. In this instance, GMusicBrowser, just because it is light weight and quick.
Then it dawned on me.... What am I doing??? I could use ssh and X11 forwarding. 
So that is what I did. 
I already had opensshserver installed on my server. X forwarding is enabled by default. So no config to mess with. 
Just simply log into the server using a command such as this:
ssh -X username@192.168.1.12 (Note that is a capital "X")
Then while connected just type in the name of the app you want to run. In this example it was gmusicbrowser. The app opened up on my local laptop and the output went to the stereo. 
That was all it took.
Here is how you can accomplish the same thing.
Once you have Ubuntu installed and patched, run this command:
sudo apt-get install tasksel
Followed by 
sudo tasksel
When you run tasksel you will get a box opened up in your shell. 
Using the arrow keys scroll down to openssh server.
Select this by pressing the space bar.
Then tab to OK and press enter.
This will install the needed packages to make your Ubuntu computer accept ssh connections.
This is all you need to do. Then you can go to your other computer and connect using a command just like the once I used above. 
ssh -X username@192.168.1.12
If you have a firewall enabled you will need to make sure that port 22 is open to allow your ssh traffic to your server.
That's it, you're all done and ready to run some apps.

Sunday, March 6, 2011

Linux SSH and the Screen command

The screen command, what is that you ask?
That is a good question. The screen command comes standard with most linux distributions. Ok, So what does it do you ask? Well it is quite simple and extremely handy to know.

Given scenario: You are tasked with copying a large amount of files from an external USB drive to one of your linux file servers. The server has no GUI installed, so you have to use the CLI. So you fire up putty and mount the drive and then you start the file copy. It is close to time for you to leave the office for the day. You know that if you close the putty session, your file copy will stop. This sucks, you figure you still have a couple of hours to wait before the copy finishes. You need to leave, and the files need to be in place by the time you get to the office in the morning. This is where screen come to the rescue.

man screen
Screen is a full-screen window manager that multiplexes a physical terminal between several processes (typically interactive shells). Each virtual terminal provides the functions of a DEC VT100 terminal and, in addition, several control functions from the ISO 6429 (ECMA 48, ANSIX3.64) and ISO 2022 standards (e.g. insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows moving text regions between windows.

Instead of immediately starting yout copy session once you have your putty session established, try this.
Start your putty session, then just type in the command "screen". You will be shown an intro window, just press space to make that go away. You now see your command prompt. Start typing, start your file copy.

Oh, you just found out you need to modify your firewall and the file copy hasn't finished yet, no worries, screen can assist you here too. Instead of opening a new putty session, just press ctrl+a and the c. This will create a new session. You will see a new prompt appear, start typing away.
While watching the logs to make sure you opened up the correct ports, you need to check on your file copy, simple. Press ctrl+a and the p to return to your previous session. To go back, press ctrl+a then n to hop in to the next session you created. Seems simple enough.

Now it is time for you to shut down for the day. Press ctrl+a then d to disconect from screen. You will return to your original session where you can then safely exit putty.

You make the commute home. Once home all safe and sound, you decide to connect to the office and check your file copy. Once again we fre up putty. Now we just need to reconnect to your screen session. Just type in screen -r. You will connected back to your screen session.
Well that was easy. There is much more functionality in screen. This is enough to get you going, and I highly recommend you spend some time looking around in the man pages to see what else you can with screen.

So leave a comment and let me know what you think. How has the screen command helped you?