RAID in Linux, using mdadm in Linux.

Linux software RAID has nothing to do with hardware RAID controllers. You don’t need an add-on controller, and you don’t need the onboard controllers that come on most motherboards.

The RAID  devices  are virtual devices created from two or more real block devices. This allows multiple devices (typically disk drives or partitions thereof) to be combined into a single device to hold (for example) a single filesystem.
Some RAID levels include redundancy and  so  can  survive some degree of device failure.

Currently, Linux supports LINEAR md devices, RAID0 (striping), RAID1 (mirroring), RAID4, RAID5, RAID6, RAID10, MULTIPATH, FAULTY, and CONTAINER.
Continue reading “RAID in Linux, using mdadm in Linux.”

Find out the subdomains of a given name with "dig"

You might find yourself in a situation that you would like to know all the listed sub-domains in a domain. If you are the administrator of the DNS server you will not have much trouble of finding the information, if you are not the administrator of the server you can have a hard time finding out the sub-domains for a domain.
First, find out the name server or servers for a domain using the dig command:
Continue reading “Find out the subdomains of a given name with "dig"”

Increase an ext2/3 partition without lossing data.

Resize ext3 partition using resize2fs which support ext3.

root@deb:/disk# ls -la
total 664228
drwxr-xr-x 3 root root 4096 Dec 19 18:29 .
drwxr-xr-x 22 root root 4096 Dec 19 17:19 ..
-rwxrwxrwx 1 nobody nogroup 679477248 Nov 26 11:31 debian-6.0.3-i386-CD-1.iso
drwx------ 2 root root 16384 Dec 19 17:18 lost+found
root@deb:/disk#

There is an ISO of Debian system. I don’t want loose it 🙂
Continue reading “Increase an ext2/3 partition without lossing data.”

LVM – create, resize, remove, scan, reduce, etc.

LVM enables flexible distribution of hard disk space over several file systems. It was developed because the need to change the segmentation of hard disk space might arise only after the initial partitioning has already been done during installation. Because it is difficult to modify partitions on a running system, LVM provides a virtual pool (volume group or VG) of memory space from which logical volumes (LVs) can be created as needed. The operating system accesses these LVs instead of the physical partitions.
Continue reading “LVM – create, resize, remove, scan, reduce, etc.”

Spying on the console.

Some software prints error messages to the console that may not necessarily show up on your SSH session. Using the vcs devices can let you examine these. From within an SSH session, run the following command on a remote server:

# cat /dev/vcs1

This will show you what is on the first console. You can also look at the other virtual terminals using 2, 3, etc. If a user is typing on the remote system, you’ll be able to see what he typed.

SSH backdoor.

SSH from hades to earth.server.com with the -R flag. I’ll assume that you’re the root user on hades and that tech will need the root user ID to help you with the system. With the -R flag, you’ll forward instructions of port 2222 on earth.server.com to port 22 on hades. This is how you set up an SSH tunnel. Note that only SSH traffic can come into hades: You’re not putting hades out on the Internet naked.

You can do this with the following syntax:

# ssh -R 2222:localhost:22 username@hades.server.com

Once you are into hades.server.com, you just need to stay logged in and enter a command like:

username@hades.server.com:~$ while [ 1 ]; do date; sleep 300; done

to keep the machine busy and minimize the window.
Now instruct your friends to SSH as “username” into earth.server.com without using any special SSH flags. You’ll have to give them your password:

root@hades:~# ssh username@earth.server.com .

BTW no need

Once user is on the hades.server.com, they can SSH to earth using the following command:

username@hades.server.com:~$: ssh -p 2222 root@localhost

Short form:

from earth: ssh -R 2222:localhost:22 username@hades.somedomain.com
then: while [ 1 ]; do date; sleep 300; done
from hades: ssh -p 2222 root@localhost
and we can log in into earth.somedomain.com :))

SSH login without password.

If you need to login from a serverA to a serverB using no password.

First what you have to do is login to a serverA as a user to generate a pair of authentication keys.
Do not enter a passphrase!

user@serverA:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Created directory '/home/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
90:48:02:a5:3a:55:28:91:e2:29:7d:f8:e6:93:a1:e4 user@serverA
user@serverA:~>

Now use the ssh to create a directory ~/.ssh as a user “user” on a serverB. The directory may already exist there, in this case do not create that directory:

user@serverA:~> ssh user@serverB mkdir -p .ssh
user@serverB password:

Finally copy a new public key to user@serverB .ssh/authorized_keys and enter the userB password the last time:

user@serverA:~> cat .ssh/id_rsa.pub | ssh user@serverB 'cat >> .ssh/authorized_keys'
user@serverB password:

From now, you can login to a serverB as a user “user” from a serverA without typing a password.

Network File System in Debian.

Installing NFS in Debian

Making your computer an NFS server or client is very easy. The Debian NFS client needs:

# apt-get install nfs-common portmap

while a Debian NFS server needs:

# apt-get install nfs-kernel-server nfs-common portmap

NFS Server Configuration.

NFS exports from a server are controlled by the file /etc/exports. Each line begins with the absolute path of a directory to be exported, followed by a space-seperated list of allowed clients.

/etc/exports
/home 192.168.1.2(rw,no_root_squash) www.domain.com(ro)
/usr 192.168.1.2/24(ro,insecure)

A client can be specified either by name or IP address. Wildcards (*) are allowed in names, as are netmasks (e.g. /24) following IP addresses, but should usually be avoided for security reasons.

A client specification may be followed by a set of options, in parenthesis. It is important not to leave any space between the last client specification character and the opening parenthesis, since spaces are intrepreted as client seperators.

For each options specified in /etc/exports file can be check export man pages.
If you make changes to /etc/exports on a running NFS server, you can make these changes effective by issuing the command:

# exportfs -a

NFS Client Configuration

NFS volumes can be mounted by root directly from the command line. For example:

# mount files.domain.com:/home /mnt/nfs

mounts the /home directory from the machine files.domain.com as the directory /mnt/nfs on the client. Of course, for this to work, the directory /mnt/nfs must exist on the client and the server must have been configured to allow the client to access the volume.

It is more usual for clients to mount NFS volumes automatically at boot-time. NFS volumes can be specified like any others in /etc/fstab.

/etc/fstab
192.168.1.3:/home /home nfs rw,rsize=4096,wsize=4096,hard,intr,async,nodev,nosuid 0 0
192.168.1.3:/usr /usr nfs ro,rsize=8192,hard,intr,nfsvers=3,tcp,noatime,nodev,async 0 0

There are two kinds of mount options to consider: those specific to NFS and those which apply to all mounts. Consider first those specific to NFS.

For each options menctioned in /etc/fstab file check the man pages of fstab.