Wednesday, 16 September 2009

3 Steps to Perform SSH Login Without Password Using ssh-keygen & ssh-copy-id


You can login to a remote Linux server without entering password in 3 simple steps using ssky-keygen and ssh-copy-id as explained in this article.

ssh-keygen creates the public and private keys. ssh-copy-id copies the local-host’s public key to the remote-host’s authorized_keys file. ssh-copy-id also assigns proper permission to the remote-host’s home, ~/.ssh, and ~/.ssh/authorized_keys.

This article also explains 3 minor annoyances of using ssh-copy-id and how to use ssh-copy-id along with ssh-agent.

Step 1: Create public and private keys using ssh-key-gen on local-host


jsmith@local-host$ [Note: You are on local-host here]

jsmith@local-host$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
33:b3:fe:af:95:95:18:11:31:d5:de:96:2f:f2:35:f9 jsmith@local-host

Step 2: Copy the public key to remote-host using ssh-copy-id


jsmith@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
jsmith@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key.



Step 3: Login to remote-host without entering the password


jsmith@local-host$ ssh remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
[Note: SSH did not ask for password.]

jsmith@remote-host$ [Note: You are on remote-host here]


The above 3 simple steps should get the job done in most cases.

We also discussed earlier in detail about performing SSH and SCP from openSSH to openSSHwithout entering password.

If you are using SSH2, we discussed earlier about performing SSH and SCP without password from SSH2 to SSH2 , from OpenSSH to SSH2 and from SSH2 to OpenSSH.



Using ssh-copy-id along with the ssh-add/ssh-agent


When no value is passed for the option -i and If ~/.ssh/identity.pub is not available, ssh-copy-idwill display the following error message.

Linux Crontab: 15 Awesome Cron Job Examples

An experienced Linux sysadmin knows the importance of running the routine maintenance jobs in the background automatically.

Linux Cron utility is an effective way to schedule a routine background job at a specific time and/or day on an on-going basis.

This article is part of the on-going Productivity Tips For Geeks series. In this article, let us review 15 awesome examples of crontab job scheduling.



Linux Crontab Format


MIN HOUR DOM MON DOW CMD






































Table: Crontab Fields and Allowed Ranges (Linux Crontab Syntax)
FieldDescriptionAllowed Value
MINMinute field0 to 59
HOURHour field0 to 23
DOMDay of Month1-31
MONMonth field1-12
DOWDay Of Week0-6
CMDCommandAny command to be executed.

1. Scheduling a Job For a Specific Time Every Day


The basic usage of cron is to execute a job in a specific time as shown below. This will execute the Full backup shell script (full-backup) on 10th June 08:30 AM.

Please note that the time field uses 24 hours format. So, for 8 AM use 8, and for 8 PM use 20.



30 08 10 06 * /home/ramesh/full-backup


  • 30 – 30th Minute

  • 08 – 08 AM

  • 10 – 10th Day

  • 06 – 6th Month (June)

  • * – Every day of the week


2. Schedule a Job For More Than One Instance (e.g. Twice a Day)


The following script take a incremental backup twice a day every day.

This example executes the specified incremental backup shell script (incremental-backup) at 11:00 and 16:00 on every day. The comma separated value in a field specifies that the command needs to be executed in all the mentioned time.



00 11,16 * * * /home/ramesh/bin/incremental-backup


  • 00 – 0th Minute (Top of the hour)

  • 11,16 – 11 AM and 4 PM

  • * – Every day

  • * – Every month

  • * – Every day of the week


3. Schedule a Job for Specific Range of Time (e.g. Only on Weekdays)


If you wanted a job to be scheduled for every hour with in a specific range of time then use the following.


Perform SSH and SCP Without Entering Password on openSSH

In this article, I’ll explain how to perform ssh and scp without entering the password using the SSH Public Key authentication with SSH Agent on openSSH


There are two levels of security in the SSH key based authentication. In order for you to login, you need both the private key and the passphrase. Even if one of them is compromised, attacker still cannot login to your account, as both of them are needed to login. This is far better than typical password based authentication, where if the password is compromised, attacker can gain access to the system.


There are two ways to perform ssh and scp without entering the password:




  1. No passphrase. While creating key pair, leave the passphrase empty. Use this option for the automated batch processing. for e.g. if you are running a cron job to copy files between machines this is suitable option.

  2. Use passphrase and SSH Agent. If you are using ssh and scp interactively from the command-line and you don’t want to use the password everytime you perform ssh or scp, I don’t recommend the previous option (no passphrase), as you’ve eliminated one level of security in the ssh key based authentication. Instead, use the passphrase while creating the key pair and use SSH Agent to perform ssh and scp without having to enter the password everytime as explained in the steps below.


Following 8 steps explains how to perform SSH and SCP from local-host to a remote-host without entering the password on openSSH system



1. Verify that local-host and remote-host is running openSSH


[local-host]$ ssh -V
OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006

[remote-host]$ ssh -V
OpenSSH_4.3p2, OpenSSL 0.9.8b 04 May 2006

2. Generate key-pair on the local-host using ssh-keygen


[local-host]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jsmith/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jsmith/.ssh/id_rsa.
Your public key has been saved in /home/jsmith/.ssh/id_rsa.pub.
The key fingerprint is:
31:3a:5d:dc:bc:81:81:71:be:31:2b:11:b8:e8:39:a0 jsmith@local-host

The public key and private key are typically stored in .ssh folder under your home directory. In this example, it is under /home/jsmith/.sshd. You should not share the private key with anybody.


By default the ssh-keygen on openSSH generates RSA key pair. You can also generate DSA key pair using: ssh-keygen -t dsa command.



3. Install public key on the remote-host.


Copy the content of the public key from the local-host and paste it to the /home/jsmith/.ssh/authorized_keys on the remote-host. If the /home/jsmith/.ssh/authorized_keys already has some other public key, you can append this to the end of it. If the .ssh directory under your home directory on remote-host doesn’t exist, please create it.



[remote-host]$ vi ~/.ssh/authorized_keys 
ssh-rsa ABIwAAAQEAzRPh9rWfjZ1+7Q369zsBEa7wS1RxzWR jsmith@local-host

In simple words, copy the local-host:/home/jsmith/.ssh/id_rsa.pub to remote-host:/home/jsmith/.ssh/authorized_keys



4. Give appropriate permission to the .ssh directory on the remote-host.


[remote-host]$ chmod 755 ~/.ssh
[remote-host]$ chmod 644 ~/.ssh/authorized_keys

5. Login from the local-host to remote-host using the SSH key authentication to verify whether it works properly.


[local-host]$ 

[local-host]$ ssh -l jsmith remote-host
Enter passphrase for key '/home/jsmith/.ssh/id_rsa':
Last login: Sat Jun 07 2008 23:03:04 -0700 from 192.168.1.102
No mail.

[remote-host]$

6. Start the SSH Agent on local-host to perform ssh and scp without having to enter the passphrase several times.


Verify whether SSH agent is already running, if not start it as shown below.



[local-host]$ ps -ef | grep ssh-agent
511 9789 9425 0 00:05 pts/1 00:00:00 grep ssh-agent

[local-host]$ ssh-agent $SHELL

[local-host]$ ps -ef | grep ssh-agent
511 9791 9790 0 00:05 ? 00:00:00 ssh-agent /bin/bash
511 9793 9790 0 00:05 pts/1 00:00:00 grep ssh-agent

7. Load the private key to the SSH agent on the local-host.


[local-host]$ ssh-add
Enter passphrase for /home/jsmith/.ssh/id_rsa:
Identity added: /home/jsmith/.ssh/id_rsa (/home/jsmith/.ssh/id_rsa)

Following are the different options available in the ssh-add:




  • ssh-add : Load a specific key file.

  • ssh-add -l: List all the key loaded in the ssh agent.

  • ssh-add -d : Delete a specificy key from the ssh agent

  • ssh-add -D: Delete all key


8. Perform SSH or SCP to remote-home from local-host without entering the password.


[local-host]$

[local-host]$ ssh -l jsmith remote-host
Last login: Sat Jun 07 2008 23:03:04 -0700 from 192.168.1.102
No mail.

[remote-host]$

Tuesday, 15 September 2009

How to check the version of Horde

If you have ‘root’ SSH access to the server then, simply open the file


# /var/cpanel/horde/version


using your favorite editor and you’ll be able to see the current Horde version.

How to disable IPv6 networking

Our policy and network configuration does not requires IPv6 support in RHEL / CentOS / Fedora Linux. How do I prevent the kernel module from loading at boot time and disable IPv6 networking?

You can easily prevent the kernel module from loading by updating the following two files:

/etc/modprobe.conf - Kernel driver configuration file.

/etc/sysconfig/network - RHEL / CentOS networking configuration file.

/etc/modprobe.conf

Edit /etc/modprobe.conf, enter:

# vi /etc/modprobe.conf

Append the following line:

install ipv6 /bin/true

Save and close the file.

/etc/sysconfig/network

Edit /etc/sysconfig/network, enter:

# vi /etc/sysconfig/network

Update / add as follows:

NETWORKING_IPV6=no

IPV6INIT=no

Save and close the file. Restart networking service

# service network restart

# rmmod ipv6

Alternatively, simple reboot the box:

# reboot

Verify IPv6 is disabled, enter:

# lsmod | grep ipv6

# /sbin/ifconfig

Monday, 14 September 2009

How to Backup & restore Linux Plesk 8 on domain level

Backup


Create backup


/usr/local/psa/bin/pleskbackup -vvv domains domain.be /home/root/psabackup

Move backup to another server


sftp root@newserverip put /home/root/psabackup

Restore


Create map file


/usr/local/psa/bin/pleskrestore --create-map /root/psabackup -map /root/backup.map

Edit map file


Edit /root/backup.map.

The value between []’s should be replaced with the client name where you want to restore to. Change IP’s by adding -> new IP.

Example; [clientname]

domain.be 85.158.105.250->85.158.105.252
mysql::@localhost:3306

Restore using map file


/usr/local/psa/bin/pleskrestore --restore /root/psabackup -level domains -verbose -map /root/backup.map

http://blog.connexeon.com/?s=Plesk

http://blog.connexeon.com/?s=Plesk