Tip: Prevent SSH Session from Disconnecting

The network connection at office keeps my SSH session from running smoothly. Well, it means I keep on being disconnected from the server when my SSH session turns idle for a certain period of time. It gets annoying especially if I am in the middle of a script running silently.

One alternative I have written before here is using screen command or by editing the SSH config file to prevent SSH from disconnecting its connection.

The process is very simple: your SSH session consistently sends packets over the connection to let the remote computer know that the session is still active and there is no need for termination. This is what they call Keep Alive packets. For me, it means Keep My Sanity packets.

Anyway here is what you need to do. Edit your ssh_config file, usually in /etc/ssh/ directory:

# vi /etc/ssh/ssh_config

And put this line in the file:

ServerAliveInterval 60

Save and exit.

Open the ~/.ssh/config file (or create it if not present) and put this line in it:

Host *
ServerAliveInterval 60

Don’t forget the indent at the second line. Save and exit.

Lastly, reload your new SSH config file by doing:

# /etc/init.d/sshd reload

This should do the trick of fooling the remote server into thinking that your SSH connection is active, even if it is not.

Did this tip worked for you? Let me know in the comments section.

Popularity: 9% [?]

Tip: Resume Session with screen

Network infrastructure is the backbone of your computer’s connectivity and therefor should be stable, reliable and very little, if no downtime. If it isn’t the case, can you imagine getting disconnected from the server while you are remotely running your scripts via ssh? Not only that the script has to be re-run, but might damage other important files as well.

If you are in a situation where you need something to remain connected to the server, you can use screen. screen is a full-screen window manager that multiplexes a physical terminal between several processes typically interactive shells). When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill existing windows, view a list of windows, turn output logging on and off, copy-and-paste text between windows, view he scrollback history, switch between windows in whatever manner you wish, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the user’s terminal. Read the rest of this entry »

Popularity: 8% [?]

Tip: How to Schedule Tasks

If you are using Windows, you are probably familiar with task scheduler to schedule certain tasks automatically. With Linux, tasks can be done on scheduled dates with cron.

cron is the service that works like task scheduler in Windows and can be used if you want to automate repetitive tasks like generating reports everyday or virus scanning. cron is handled by the cron daemon or crond, which should be running if you want your scheduled tasks to run.
Read the rest of this entry »

Popularity: 6% [?]

Tip: How to Delete Files with Special Characters

How to delete files with dash or any special character?

Have you tried to delete a who-knows-where-it-came-from file which has a special character like preceded with dash or question mark? I bet that when you tried to delete it, you got something like this:
Read the rest of this entry »

Popularity: 13% [?]

Ultimate Linux Cheat Sheets

If you are in dire need of SOS because of that little command that is stuck at the tip of your tongue or you are having a huge case of memory gap, fret not. Here is a quick link to a massive list of Unix/Linux cheat sheets. One link points to http://www.tuxfiles.org/linuxhelp/linuxcommands.html which profiles a list of Linux commands that are newbie friendly.

List too long for you? You can try the Linux command apropos <keyword>. This command searches the whatis database for strings that matches your keyword. Let’s say you forgot the command to copy a file (uh-oh) so we go like this:

# apropos copy

# cp (1) - copy files and directories
# cp (1p) - copy files

Hey there it is! ;) So we got cp. You can now use man command to check if cp is really what you are looking for. Google is also a neat tool if internet access is readily available. :D

Popularity: 10% [?]