Thursday, December 23, 2010

Remove Last Login Information in Linux

Linux holds all the log files in /var/log directory. You just need to find out which log file you require. Generally, two files hold the login information on a linux system-

lastlog
wtmp

cd /var/log/
rm -rf lastlog
rm -rf wtmp
touch lastlog
touch wtmp
chmod 644 wtmp (optional)
chmod 644 lastlog (optional)
exit

TOUCH command is used to create both the file with an empty content.
Setting permission to both the files are optional.

Friday, October 1, 2010

IPTRAF - Bandwidth Usage Monitor In Linux

If you are a Sysadmin in a company and have a Linux based network, how will you determine quickly what is getting downloaded on a particular user system? In my office we have a bandwidth monitor graph that shows the total download and upload usage of an INTERNET connection with BLUE(download) and GREEN(upload) lines in realtime(updates at every second). But this shows the total usage in the entire office. Sometimes I see that the download on a specific connection goes very high(as blue line goes high). That means that one or more system(s) is downloading a big file from the web. This is really annoying as it eats up the bandwidth resulting into slow connection.

What to do? How to detect it without physically visiting each and every desk?

Simple ....  IPTRAF is the solution.


Just install IPTRAF of your linux based Internet Sharing Server and you can get all the bandwidth usage related information of each and every system connected with that.

IPTRAF

Installation : Download the rpm package and install with yum on the ISS Server.

How to use

1. Log-in on the ISS Server through ssh.
2. Give the command iptraf at the prompt.
3. Iptraf interface will open. Press any key to continue.
4. Next you will see the Menu of Iptraf.
5. Press enter on IP Traffic Monitor.
6. Go through the applicable network interface i.e the interface you want to monitor (eth0, eth1, lo,). You can select All Interfaces in case you want to monitor the lan, wan and the local loop together.

Lets take the eth1 as an example. Suppose eth1 is the LAN connection in your office. Now when you will choose the eth1 interface to monitor, it will show the IP of the systems currently connected with the server. You can do a "sort by packet" / "sort by bytes" to sort out the local IP of the systems consuming the highest bandwidth in an decreasing order.

Each and every system IP will be connected with a Public IP. This public IP is the IP of the website they are connected with at present. Hence, in this way you can quickly determine the system that would be affecting the internet speed by downloading big files.

Tuesday, September 14, 2010

Alias - A Great Tool

"Alias" in Linux has its own importance. It was helpful to me by the following means-

1. Saves time by reducing the typing.
2. No need to remember typical commands, paths.
3. No need to remember IP addresses of all the servers(where there is question of maintaining more than 50 servers)

alias ='command'

Here,

shortcut refers to the convenient word to be used instead of typing the whole command.

For example, if you need to login to a server through ssh , generally you type-

ssh -p 99 username@servername or ipaddress

With alias, you can bind this entire command to just a single word of your choice.

alias ns='ssh -p 99 username@servername or ipaddress'

Now you can simply type ns in the shell and it will directly connect you to the server. No need to type the entire ssh command each and every time login is required.


Few More Examples -

Bind a long typical path (which you use very frequently) with alias

alias domain='/var/www/html/manage/network/domains/'


Typing domain at the shell will directly put you inside the directory domains which is located at /var/www/html/manage/network/domains/

alias l='ls -la'

This will execute the command ls -la everytime you just type l.





Tuesday, August 31, 2010

Login To A Linux Server Without Password

Lets suppose that you need to run a command to update a module on multiple servers via ssh. Though using parallel ssh to save time, you would require to provide passwords on each server each time you will login. So the ultimate problem still remains their. Hows that if it would be possible that you run the command through parallel ssh and the operation went on smoothly without asking for any password..

Here how it would be-

1. Generate a pair of authentication keys. Give the command as below-

Note: even if is unsecured to work without password, do not enter it. Let it empty...


ssh-keygen -t rsa
You will get the output as below-
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
31:df:a5:73:4a:2f:a6:6c:1c:32:a2:f2:b3:c5:a7:1f user1@computer1

The above command will generate id_rsa.pub key file in your /home/user1/.ssh folder

2. Now you need to copy this file to the ssh folder in the target server. Follow the command below-

cat .ssh/id_rsa.pub |ssh -p 99 root@72.52.93.20 'cat >> .ssh/authorized_keys'

where -

* -p is used to define port number of ssh.
* 99 is the port number.
* id_rsa.pub is the key file.
* root is the username to login with.
* 72.52.93.20 is the IP of the target server.
* .ssh/ is the ssh folder under root directory.
* authorized_keys is the id_rsa.pub file copied as authorized_keys on target server.

The CAT command will copy the id_rsa.pub file as authorized_keys file on the target server. You will be asked for the password while copy. 

If you wish you can restrict this file to be accessed by you only by setting the permission.

chmod 644 *

Now  you can try login to the server by typing its IP or name at your terminal and it should logged-in directly without asking for any password.

Parallel SSH

Well everybody knows what to do with ssh but what if you need to run a pair of commands on multiple servers ?

Login to each server through ssh and running that command will become a funny business. Isn't?

So here is the tool that can serve commands on multiple servers at the same time.


PARALLEL SSH

Installation

http://www.linux.com/archive/feature/151340

http://www.theether.org/pssh/


Operating PSSH

(in Ubuntu)

parallel-ssh -h hostfile.txt -l username -i -o /path_of_log_folder/folder command



where-

* -h indicates to the host file that contains the list of host servers.

* iplist.txt is the host file that contains the IP addresses (with port number for ssh) of the servers on which the command is to be run.

* -l indicates the next string as the username to be logged-in with.
* -i option in the displays the result of the execution on each server.
* -o specifies the path next to it where the output of the operation (log report)is saved in particular text files.

parallel-ssh -h iplist.txt -l root -i -o /home/robert/checklist/webmin rpm -q webmin

This command (rpm -q webmin) will check the version of webmin on all the servers listed in the iplist.txt file by logging-in with username as root and will generate the output of each server in particular files under folder webmin which is located at  /home/robert/checklist/

Working Out with Virtual Containers on Linux

Viewing List of running Containers on a system

Login to the base system via putty and type-

xm list

Starting UP a container

First go to the path of the container where it is located.

cd /etc/xen/auto

xm create (cont.name)



Shutting DOWN a container



xm shutdown (cont.name or id)





Forcefully Quitting The Container



xm destroy (cont.name or id)



Friday, October 2, 2009

Common Troubleshooting

Able to ping a website but its not opening in browser.

Possibilities : Deposition of browser cache, DNS cache, Cookies etc.

Shooting :
1. Try first by clearing the cache from the browser.
2. Try by clearing the DNS cache from the system.
         c:\>ipconfig /flushdns
3. Enable /disable the internet connection.
4. Download winsockproxy software to fix this bug if happening regularly.

Friday, September 25, 2009

Some Important DOS Commands

Command to view a process running on a specific network (TCP/UDP) port :


netstat -anno
 


To kill a process from DOS mode

c:/ taskkill /F /PID (pid no.)

Friday, September 11, 2009

Configuring SNMP (Simple Network Management Protocol)



switch(config)# snmp-server community (name)

switch(config)# snmp-server enable traps authentication

Thursday, September 10, 2009

Using SVN

Adding a newly created file in SVN

svn add (filename)

Committing a file in main SVN
svn ci -m "message"


Deleting a file from SVN

svn del


To update a directory from a updated revision on svn server
cd
svn up




Restoring a directory with the latest revision -
svn checkout

To get the path of the directory stored in the svn server-
cd
svn info