Tips & Tricks
Secure your Linux server with auto logout
The root account is the most privileged account on a *nix system and has no security restrictions imposed upon it. This means the system assumes you know what you are doing, and will do exactly what you request it to do. Therefore it is easy, with just a mistyped command, to wipe out crucial system files. When using this account, it is important to be as careful as possible. For security reasons, it is recommended not to log in on your server as the root unless it is absolutely necessary. Now, let us look at how to set the login time out for the root account.
We often log in to the terminal as the root and leave it unattended or forget to log out after finishing our work, often leaving the terminal unattended.
Here is a tip that will solve this problem by automatically logging you out after a specified period of time. To do that, you must set the special variable TMOUT.
Edit the profile file and add the following line somewhere:
The value we enter for the variable ‘TMOUT=’ is in seconds and represents two hours (60 * 60 =3600 * 2 = 7200 seconds). It is important to note that if you decide to put the above line in your /etc/profile file, then the automatic logout after two hours of inactivity will apply for all users on the system. So, instead, you may prefer to control which users will be automatically logged out and which ones will not. You can set this variable in their individual .bashrc files.
Display coloured man pages
To display colours in man pages, use an application called most. In Debian-based GNU/Linux, you can install this package by using the following command:
Browse a tarfile with VIM
You can browse a tarfile with VIM, without extracting it, as shown below:
cbrowser-0.8 is a directory and the files in this directory are listed below it. You can select the file and press Enter to open them in VIM.
Back up and restore permissions of directories
To back up permissions of a directory, use the getfacl command. getfacl gets file access control lists. Here, you will get the acl and store it in a file as shown below:
Change the permissions as you wish and when it’s time to restore the permissions, you can easily get back to the original permissions by using the following command:
Efficient browsing of source code using vim-taglist
Taglist gives an overview of the structure of the source file and allows you to jump to a particular function of a source code. This makes navigation through a source file easy and efficient.
Installation: Download the plugin taglist.zip from http:// sourceforge.net/projects/vim-taglist/files/ and unzip the files in $HOME/.vim. This will create two files:
Now restart the vim and open any source file (hello.c). If you run the following command:
…you should see the taglist window. You can navigate to any particular index on the taglist just by pressing Enter. The taglist plug-in requires ctags to operate. Make sure you have ctags before using the taglist. You can open the tag in a new horizontal window by pressing ‘o’ instead of the Enter key.
Here is an example of .vimrc configuration for a taglist plug-in:
Note: 1. To enable copying in Visual mode from Vim to a different application, you need to have a Vim version in which system-wide clipboard is supported. A system-wide clipboard is available if you see +xterm_ clipboard when you run :version in the command mode of Vim. While running Vim, if you see -xterm_clipboard, then install Vim from source by providing xterm_ clipboard in the configuration file as an additional option. 2. If you are using screen, you need to change the key bindings, as Alt + Right/Left Arrow is bound to some other function in screen. 3. Mouse movements are not possible if you are using
ssh to a remote machine running Vim.
Hope this information will be useful for you.