Tips & Tricks

OpenSource For You - - CONTENTS - —Udaya Sankar, [email protected] —Naren­dra Kan­gralkar, naren­drakan­[email protected]

Se­cure your Linux server with auto lo­gout

The root ac­count is the most priv­i­leged ac­count on a *nix sys­tem and has no se­cu­rity re­stric­tions im­posed upon it. This means the sys­tem as­sumes you know what you are do­ing, and will do ex­actly what you re­quest it to do. There­fore it is easy, with just a mistyped com­mand, to wipe out cru­cial sys­tem files. When us­ing this ac­count, it is im­por­tant to be as care­ful as pos­si­ble. For se­cu­rity rea­sons, it is rec­om­mended not to log in on your server as the root un­less it is ab­so­lutely nec­es­sary. Now, let us look at how to set the lo­gin time out for the root ac­count.

We of­ten log in to the ter­mi­nal as the root and leave it unat­tended or for­get to log out af­ter fin­ish­ing our work, of­ten leav­ing the ter­mi­nal unat­tended.

Here is a tip that will solve this prob­lem by au­to­mat­i­cally log­ging you out af­ter a spec­i­fied pe­riod of time. To do that, you must set the spe­cial vari­able TMOUT.

Edit the pro­file file and add the fol­low­ing line some­where:

The value we en­ter for the vari­able ‘TMOUT=’ is in sec­onds and rep­re­sents two hours (60 * 60 =3600 * 2 = 7200 sec­onds). It is im­por­tant to note that if you de­cide to put the above line in your /etc/pro­file file, then the au­to­matic lo­gout af­ter two hours of in­ac­tiv­ity will ap­ply for all users on the sys­tem. So, in­stead, you may pre­fer to con­trol which users will be au­to­mat­i­cally logged out and which ones will not. You can set this vari­able in their in­di­vid­ual .bashrc files.

Dis­play coloured man pages

To dis­play colours in man pages, use an ap­pli­ca­tion called most. In De­bian-based GNU/Linux, you can in­stall this pack­age by us­ing the fol­low­ing com­mand:

Browse a tarfile with VIM

You can browse a tarfile with VIM, without ex­tract­ing it, as shown be­low:

cbrowser-0.8 is a di­rec­tory and the files in this di­rec­tory are listed be­low it. You can se­lect the file and press En­ter to open them in VIM.

Back up and res­tore per­mis­sions of di­rec­to­ries

To back up per­mis­sions of a di­rec­tory, use the get­facl com­mand. get­facl gets file ac­cess con­trol lists. Here, you will get the acl and store it in a file as shown be­low:

Change the per­mis­sions as you wish and when it’s time to res­tore the per­mis­sions, you can eas­ily get back to the orig­i­nal per­mis­sions by us­ing the fol­low­ing com­mand:

Ef­fi­cient brows­ing of source code us­ing vim-taglist

Taglist gives an over­view of the struc­ture of the source file and al­lows you to jump to a par­tic­u­lar func­tion of a source code. This makes nav­i­ga­tion through a source file easy and ef­fi­cient.

In­stal­la­tion: Down­load the plugin taglist.zip from http:// source­forge.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 fol­low­ing com­mand:

…you should see the taglist win­dow. You can nav­i­gate to any par­tic­u­lar in­dex on the taglist just by press­ing En­ter. The taglist plug-in re­quires ctags to op­er­ate. Make sure you have ctags be­fore us­ing the taglist. You can open the tag in a new hor­i­zon­tal win­dow by press­ing ‘o’ in­stead of the En­ter key.

Here is an ex­am­ple of .vimrc con­fig­u­ra­tion for a taglist plug-in:

Note: 1. To en­able copy­ing in Vis­ual mode from Vim to a dif­fer­ent ap­pli­ca­tion, you need to have a Vim ver­sion in which sys­tem-wide clip­board is sup­ported. A sys­tem-wide clip­board is avail­able if you see +xterm_ clip­board when you run :ver­sion in the com­mand mode of Vim. While run­ning Vim, if you see -xter­m_­clip­board, then in­stall Vim from source by pro­vid­ing xterm_ clip­board in the con­fig­u­ra­tion file as an ad­di­tional op­tion. 2. If you are us­ing screen, you need to change the key bind­ings, as Alt + Right/Left Ar­row is bound to some other func­tion in screen. 3. Mouse move­ments are not pos­si­ble if you are us­ing

ssh to a re­mote ma­chine run­ning Vim.

—Shashidhar G, gshashid­[email protected]

Hope this in­for­ma­tion will be use­ful for you.

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.