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



Wednesday, September 9, 2009

Basics of Configuring HP Procurve Managed Switches 2500 series

How to connect with the switch and configure the settings through TELNET ?

Open the command prompt and type as -
c:\ telnet (ip address of the switch)

Note : The system to which the switch is connected must be in the same IP subnet mask. For e.g

Switch IP   : 10.1.33.4
Systems IP : 10.1.33.2
Subnet Mask : 255.255.255.0 (in both)

After connecting with the switch through TELNET, you will find a screen like below-

 
or a screen like this 



Basic Setup

After entering the switch's interface through telnet (as shown above), follow the guide below to configure the basic settings of the switch through telnet.

Setting up the primary information.

At the switch prompt, type setup to enter in the switch setup mode. There you can provide the switch name, password, IP address etc.

Information can be entered through the web-interface of the switch running in a browser also but the web-interface must be enabled first. 

Enabling the web-interface management console from telnet


Follow the commands -

switch# config
switch(config)# write memory

This will save the current configuration of the switch to the flash. Now type the IP address of the switch in a browser to gain access to the web-interface and managing the switch from a GUI.

Assigning IP to HP Procurve managed switches.

How to configure a HP Procurve switch when the IP address is not known ?

Download a TFTPD Server and configure the server (tftpd32) as -

IP pool starting address : IP series like 192.168.1.1 (the system IP must be in the same mask.)
Size of pool                   : 5
Mask                            : 255.255.255.0

and Save it.

Then hold the reset and clear buttons of the switch together and release the clear button first and then the reset button once the switch is restarted. This will clear all the pre-configured settings of the switch. Then connect the switch with the system running the TFTPD server through RJ45 cable. The switch will grab one IP address from the range provided to the IP pool. Now you have the IP address of the switch to carry on further operations.