Powered By Blogger

Friday, 25 May 2012

Normalizing terminal prompt (or putty prompt) after catting a binary file

Some binaries or some command output (unexpected) can contain control sequence which can cause a terminal to interpret it as changing character set. That's why the prompt becomes unreadable and keystrokes abnormal (lines).

To fix this, there are few possible solutions:

 $ echo -e '\017'
or
 $ reset
or
 $ stty sane

Monday, 14 May 2012

How to fix ssh timeout problems


 There are 2 ways to fix it.

    1,Server Fix
    2,Client Fix

            Only need to do one of them .For server fix  you’ll need root access, so  it’s probably safer to do the client fix rather than the server fix.

    SERVER FIX.
  • On the server, login as root and edit /etc/ssh/sshd_config and add the line:
    ClientAliveInterval 60
     Restart sshd on the server after you save the file.

    CLIENT FIX
     
  •  The other wayis for your desktop machine to send those keep alive messages. As root on your desktop (or client) machine, edit /etc/ssh/ssh_config and add the line:
    ServerAliveInterval 60
    That will send send a message to the server every 60 seconds, keeping the connection open.

Friday, 11 May 2012

Runlevel in Ubuntu

                    In various linux flavours runlevels are set in /etc/inittab file.But in Ubuntu there is no /etc/inittab  because Ubuntu uses upstart to define startup services and runlevel.
     
  Anyway, you can still use inittab,by  simply create one. By default ubuntu uses
/etc/init/rc-sysinit.conf instead of /etc/inittab.
 
One can read more deatils in  /usr/share/doc/upstart/README.Debian.gz
 
And keep in mind that Ubuntu do not use standard runlevel meaning as other 
linux distros/unix OS.
Old standard was:
  • 0 - shutdown
  • 1 - single user mode
  • 3 - multiuser text mode
  • 5 - multiuser graphical mode
  • 6 - reboot
but Ubuntu uses:
  • 0 - shutdown
  • 1 - single user mode
  • 2 - multiuser graphical mode
  • 6 - reboot

Runlevel

A runlevel is a preset operating state on a Unix-like operating system.
A system can be booted into (i.e., started up into) any of several runlevels, each of which is represented by a single digit integer. Each runlevel designates a different system configuration and allows access to a different combination of processes (i.e., instances of executing programs).
The are differences in the runlevels according to the operating system. Seven runlevels are supported in the standard Linux kernel (i.e., core of the operating system). They are:

0 - System halt; no activity, the system can be safely powered down.
1 - Single user; rarely used.
2 - Multiple users, no NFS (network filesystem); also used rarely.
3 - Multiple users, command line (i.e., all-text mode) interface; the standard runlevel for most Linux-based server hardware.
4 - User-definable
5 - Multiple users, GUI (graphical user interface); the standard runlevel for most Linux-based desktop systems.
6 - Reboot; used when restarting the system.
By default Linux boots either to runlevel 3 or to runlevel 5. The former permits the system to run all services except for a GUI. The latter allows all services including a GUI.
In addition to the standard runlevels, users can modify the preset runlevels or even create new ones if desired. Runlevels 2 and 4 are usually used for user defined runlevels.
The program responsible for altering the runlevel is init, and it can be called using the telinit command. For example, changing from runlevel 3 to runlevel 5, which allows the GUI to be started, can be accomplished by the root (i.e., administrative) user by issuing the following command:
telinit 5
Booting into a different runlevel can help solve certain problems. For example, if a change made in the X Window System configuration on a machine that has been set up to boot into a GUI has rendered the system unusable, it is possible to temporarily boot into a console (i.e., all-text mode) runlevel (i.e., runlevels 3 or 1) in order to repair the error and then reboot into the GUI. The X Window System is a widely used system for managing GUIs on single computers and on networks of computers.
Likewise, if a machine will not boot due to a damaged configuration file or will not allow logging in because of a corrupted /etc/passwd file (which stores user names and other data about users) or because of a forgotten password, the problem can solved by first booting into single-user mode (i.e. runlevel 1).
The runlevel command can be used to find both the current runlevel and the previous runlevel by merely typing the following and pressing the Enter key:
/sbin/runlevel
The runlevel executable file (i.e., the ready-to-run form of the program) is typically located in the /sbin directory, which contains mostly administrative tools and which by default is not in the user's PATH (i.e., the list of directories in which the system searches for programs). Thus, it is usually necessary to type the full path of the command as shown above rather than just the name of the command itself.
The default runlevel for a system is specified in the /etc/inittab file, which will contain an entry such as id:3:initdefault: if the system starts in runlevel 3, or id:5:initdefault: if it starts in runlevel 5. This file can be easily (and safely) read with a command such as cat, i.e.,
cat /etc/inittab
As an alternative to telinit, the runlevel into which the system boots can be changed by modifying /etc/inittab manually with a text editor. However, it is generally easier and safer (i.e., less chance of accidental damage to the file) to use telinit. It is always wise to make a backup copy of /etc/inittab or any other configuration file before attempting to modify it manually.

Tuesday, 1 May 2012

Linux Set Date


Use the following syntax to set new data and time:
date --set="STRING"
For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"
You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"

Linux Set Time

To set time use the following syntax:
# date +%T -s "10:13:13"