Computer Export Solutions Windows ,Linnux,CCNA,MCSE,MCITP,JAVA,.NET Tutorial
Wel Come
Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts
Tuesday, March 8, 2011
Redhat KickStart Installation step by step guide
1. Create a kickstart file.
2. Create a boot media with the kickstart file or make the kickstart file available on the network.
3. Make the installation tree available.
4. Start the kickstart installation.
Genral Installation and automatic creation of kickstart file
step 1 : Connect system to DHCP network
Step 2 : Boot your system using Redhat boot media.
Step 3 : Enter command "linux askmethod" at boot prompt and press enter.
step 4 : Follow the installation process till it asks for Installation Method.
The options for installation method incude.
Local CDROM
Hard Drive
NFS Image ( Network installation )
FTP ( Network installation )
HTTP ( Network installation )
Select your method and install accordingly.
After installation /root/anaconda-ks.cfg file is automatically created during Install.
/root/anaconda-ks.cfg can be used as a template for future installation.
It is a scripted installation process.
we can manually configure with System-Config-Kickstart
Check systax of Kickstart file with : ksvalidator
Once you are ready with Kickstart file lets start installation with Kickstart file.
for installation with kickstart we should give following command at boot prompt
linux ks= Url
Ks will queries DHCP for kickstart location
URl gets file via HTTP or FTP or NFS.
we can also give local address like
KS=floppy; ks=Cdrom or ks= hd:device:/path of the file.
Using a NFS Server
Verify that the first two lines of the file look like this or else you may be prompted for NFS ISO file location information.
install
nfs --server=192.16.1.100 --dir=/data/network-install/ISO
example : linux ks=nfs:192.168.1.100:/kickstart/ks.cfg
Run this at boot prompt with your settings for NFS ks installation
Using a Web Server
Verify that the first two lines of the file look like this or else you may be prompted for RPM base file location information.
install
url --url http://192.168.1.100/network-install/
example : linux ks=http://192.168.1.100/network-install/kickstart/ks.cfg
Run this at boot prompt with your settings for http ks installation
Comming to Kickstart file it consists of three sections
1 command section
2 packages section
3 scripts section
Note 1: Do not change the order of the entries in the kickstart configuration file.
Note 2: The IP address you assign must be on the same subnet as that of the DHCP server for kickstart to work. If the server is going to reside on a different network after the installation, then you have to run a separate script to change the IP addressing information after the installation is complete.
Tuesday, February 1, 2011
How to install Linux operating system
To install using one of these methods, you must create a boot CD or USB boot. You do this by downloading an image file from a Mandrill mirror site and copying it to disk or USB key. These files are located in / or i586/install/images/x86_64/install/images depending on the version you want to install. The image for the CD boot boot.iso call’d, and one for the USB all.img.
Thus, for example, the image file to a CD from the i586 version of Mandriva Linux 2007 is in / on any MandrivaLinux/official/2007.0/i586/install/images/boot.iso Mandriva mirror site.
To boot from the CD image, burn the iso as an image (not as a file) on a CD or DVD recordable / rewritable using your favorite burning software, then reboot with the CD in the drive. if the installation does not start, refer to # Mandriva Linux installation does not start when the system starts with the CD or DVD in the player above.
To boot from a USB key, use the dd command (on Linux) to write the image on the key. You must know the correct device node for USB key – usually / dev/sda1, but it may be different if you use other USB storage devices, SCSI or SATA on your system. Be very careful in copying the image on a SCSI or SATA hard disk you’ll make it unbootable and destroy data. The command to use is:
dd if = all.img of = / dev/sda1
by replacing the device node with the correct value. After writing the image, reboot the system with the USB connected. To write the image file on the USB drive in Windows, see WinImage.
If the installation does not start, refer to # Mandriva Linux installation does not start when the system starts with the CD or DVD in the player above and select the USB as first boot device. Please note that some systems cannot boot from a USB storage device, and the boot device USB floppy drive is different from the boot device to USB. If your system can not boot from a USB key, you must use another method of installation.
In all cases, you are now entering the process of installing Mandriva Linux and the choice is given to the installation method to use.
There are two main ways to install on the hard drive: you can either install from a local mirror of the tree of Mandriva Linux (which you previously recreated by downloading the entire tree from a public mirror, using for example rsync), or you can install directly from the images to CD / DVD format. ISO of Mandriva Linux without burning them to disc.
Join Orkut
Thus, for example, the image file to a CD from the i586 version of Mandriva Linux 2007 is in / on any MandrivaLinux/official/2007.0/i586/install/images/boot.iso Mandriva mirror site.
To boot from the CD image, burn the iso as an image (not as a file) on a CD or DVD recordable / rewritable using your favorite burning software, then reboot with the CD in the drive. if the installation does not start, refer to # Mandriva Linux installation does not start when the system starts with the CD or DVD in the player above.
To boot from a USB key, use the dd command (on Linux) to write the image on the key. You must know the correct device node for USB key – usually / dev/sda1, but it may be different if you use other USB storage devices, SCSI or SATA on your system. Be very careful in copying the image on a SCSI or SATA hard disk you’ll make it unbootable and destroy data. The command to use is:
dd if = all.img of = / dev/sda1
by replacing the device node with the correct value. After writing the image, reboot the system with the USB connected. To write the image file on the USB drive in Windows, see WinImage.
If the installation does not start, refer to # Mandriva Linux installation does not start when the system starts with the CD or DVD in the player above and select the USB as first boot device. Please note that some systems cannot boot from a USB storage device, and the boot device USB floppy drive is different from the boot device to USB. If your system can not boot from a USB key, you must use another method of installation.
In all cases, you are now entering the process of installing Mandriva Linux and the choice is given to the installation method to use.
There are two main ways to install on the hard drive: you can either install from a local mirror of the tree of Mandriva Linux (which you previously recreated by downloading the entire tree from a public mirror, using for example rsync), or you can install directly from the images to CD / DVD format. ISO of Mandriva Linux without burning them to disc.
Join Orkut
Thursday, January 27, 2011
Backup MBR in Linux
MBR is short for Master Boot Record. It is a very small program which is located in your hard disk and executes when a computer boots up, before the operating system. Typically, it is at the first sector on your hard disk and the size is 512 bytes. The MBR maintains the DPT (Disk Partition Table), which can contains 4 primary partitions, and start the operating system. If the MBR is damaged, your operating system wouldn't be able to boot up.
Why should you backup the MBR?
Since the MBR records some information about your hard disk partitions and it loads the operating system, it is very important for a computer. Some virus can damage the MBR. They can modify the MBR so that they can start before the operating system. Or it makes your computer not to be able to run. Reinstall the operating system can solve this problem but it takes too long time. In fact, if you backup the MBR, the solution is very easy: just restore it.
How to backup MBR in Linux?
Linux or Unix provides "dd" tool to backup any file. Usually, you must be "root" so that you can use it. Before you try it, you must know it is a dangerous command, any mistake may damage your hard disk. BE CAREFUL! To backup the MBR, open the terminal and execute the following command:
dd if=/dev/sda of=~/mbr.img bs=512 count=1
Here, I suppose your hard disk is /dev/sda. It means that copy 1 block (count=1) from /dev/sda (if=/dev/sda) to ~/mbr.img (of=~/mbr.img) and the block size is 512 bytes (bs=512). After that, you can see "mbr.img" in your home directory. Its content is MBR.
Notes: Since the MBR doesn't belong to any partition, you should use if=/dev/sda, or /dev/sdb, /dev/hda, etc, instead of /dev/sda1, /dev/sdb1... You must pay attention to the "of" and "if" arguments. For example, if you type this:
dd of=/dev/sda if=~/yourfile bs=512 count=1 (DON'T try it!)
It means reading 512 bytes of ~/yourfile and writing it to /dev/sda. If ~/yourfile is a normal file instead of MBR, your MBR will be damaged. In fact, it will covers the MBR with ~/yourfile. You will find the operating system can't start next time.
How to restore MBR in Linux?
Since if the MBR is damaged, the operating system can't boot up. You need a Linux live CD to start your computer. Linux live CD is a CD that contains Linux operating system. It doesn't need to be installed on your hard disk an can be run from CDROM directly. For example, Puppy Linux. I strongly advise you to make a live CD in advance. To boot from a live CD, insert the CD into your CDROM and make sure the first boot device is the CDROM (you can change the order of boot devices in BIOS). Then restart the computer. After a while, you will enter Linux environment. For example, if the MBR image file (mbr.img) was at /home/admin/mbr.img and /dev/sda5 was mounted as /home. You should mount /dev/sda5 at first.
Step 1. Open terminal and execute the following command to make a directory:
mkdir tmp
Step 2. Mount /dev/sda5 to the "tmp" directory:
mount /dev/sda5 tmp
Step 3. Change the current directory to tmp/admin:
cd tmp/admin
Step 4. Restore the MBR:
dd of=/dev/sda if=mbr.img bs=512 count=1
After that you can reject the live CD and restart your computer. If there are not other problems, your computer will work again.
Joinn Orkut
Why should you backup the MBR?
Since the MBR records some information about your hard disk partitions and it loads the operating system, it is very important for a computer. Some virus can damage the MBR. They can modify the MBR so that they can start before the operating system. Or it makes your computer not to be able to run. Reinstall the operating system can solve this problem but it takes too long time. In fact, if you backup the MBR, the solution is very easy: just restore it.
How to backup MBR in Linux?
Linux or Unix provides "dd" tool to backup any file. Usually, you must be "root" so that you can use it. Before you try it, you must know it is a dangerous command, any mistake may damage your hard disk. BE CAREFUL! To backup the MBR, open the terminal and execute the following command:
dd if=/dev/sda of=~/mbr.img bs=512 count=1
Here, I suppose your hard disk is /dev/sda. It means that copy 1 block (count=1) from /dev/sda (if=/dev/sda) to ~/mbr.img (of=~/mbr.img) and the block size is 512 bytes (bs=512). After that, you can see "mbr.img" in your home directory. Its content is MBR.
Notes: Since the MBR doesn't belong to any partition, you should use if=/dev/sda, or /dev/sdb, /dev/hda, etc, instead of /dev/sda1, /dev/sdb1... You must pay attention to the "of" and "if" arguments. For example, if you type this:
dd of=/dev/sda if=~/yourfile bs=512 count=1 (DON'T try it!)
It means reading 512 bytes of ~/yourfile and writing it to /dev/sda. If ~/yourfile is a normal file instead of MBR, your MBR will be damaged. In fact, it will covers the MBR with ~/yourfile. You will find the operating system can't start next time.
How to restore MBR in Linux?
Since if the MBR is damaged, the operating system can't boot up. You need a Linux live CD to start your computer. Linux live CD is a CD that contains Linux operating system. It doesn't need to be installed on your hard disk an can be run from CDROM directly. For example, Puppy Linux. I strongly advise you to make a live CD in advance. To boot from a live CD, insert the CD into your CDROM and make sure the first boot device is the CDROM (you can change the order of boot devices in BIOS). Then restart the computer. After a while, you will enter Linux environment. For example, if the MBR image file (mbr.img) was at /home/admin/mbr.img and /dev/sda5 was mounted as /home. You should mount /dev/sda5 at first.
Step 1. Open terminal and execute the following command to make a directory:
mkdir tmp
Step 2. Mount /dev/sda5 to the "tmp" directory:
mount /dev/sda5 tmp
Step 3. Change the current directory to tmp/admin:
cd tmp/admin
Step 4. Restore the MBR:
dd of=/dev/sda if=mbr.img bs=512 count=1
After that you can reject the live CD and restart your computer. If there are not other problems, your computer will work again.
Joinn Orkut
Backup Your Files with 'tar' in Linux
The easiest way to back up your files is just copying. But if you have too many files to backup, copying and restoring may take too long time and it is not convenient. If there is a tool that can put many files into one file, the world will be better. Fortunately, 'tar' is used to create archive files. It can pack files or directories into a 'tar' file. It is like WinZip in Windows, but without compression.
How to create an archive file?
The most simple way to create an archive file with 'tar' is: tar -cf foo.tar file1 file2 ... Here, foo.tar is the name of the tar file you want and file1, file2... are the files you want to back up. The argument 'c' means 'create' and 'f' means 'filename'. After that, tar will generate foo.tar which contains file1, file2....
By the way, the suffix '.tar' is not necessary, it is just a good habit. Although you can specify the files you want to backup, the more usual usage of 'tar' is packing a directory, including its sub-directories and files: tar -cf foo.tar directory_name. So put your files into a directory before using tar is a good habit.
If you have installed gzip and bzip2 (almost all Unix/Linux include them), tar can call them directly to compress. i.e. create a '.tar.gz' or '.tar.bz2' file. The argument 'z' stands for 'gzip': tar -czf foo.tar.gz directory_name and 'j' means 'bzip2': tar -cjf foo.tar.bz2 directory_name. Since compression is a hard task for CPU, this will take more time. But it can save much disk space indeed.
Restoring
Restoring means extracting files from a tar file. To extract files into the current directory from a normal tar file (without compression), just use 'x' argument. For example: tar -xf foo.tar. If you want to extract to another directory, you need '-C' (uppercase) argument. For example, tar -xf foo.tar -C /opt/foo will put the files into /opt/foo directory (make sure you have enough permission to write /opt/foo).
If the tar file is compressed, you need know its format, gzip or bzip2. Usually you can know it through the file's suffix. To extract from '.tar.gz' file, use 'z' argument and to extract from '.tar.bz2', use 'j'. 'tar' will call gunzip or bunzip2 automatically.
tar -zxf foo.tar.gz
tar -jxf foo.tar.bz2
How to view a tar file?
For some reasons, you want to know what a tar file includes but you don't want to extract files from it. What you need is 't' argument. It will list the files and directories that a tar file contains:
tar -tzf foo.tar.gz
Some tricks
If the files you want to backup is too large or too many, it may take very long time. You can add '&' to make tar run in the background, so you can continue to do other work.
tar -czf foo.tar.gz foo &
If you like to print the file that tar is processing currently, you can use 'v' argument:
tar -xzvf foo.tar.gz
It will show a list of files on the screen.
Join Orkut
How to create an archive file?
The most simple way to create an archive file with 'tar' is: tar -cf foo.tar file1 file2 ... Here, foo.tar is the name of the tar file you want and file1, file2... are the files you want to back up. The argument 'c' means 'create' and 'f' means 'filename'. After that, tar will generate foo.tar which contains file1, file2....
By the way, the suffix '.tar' is not necessary, it is just a good habit. Although you can specify the files you want to backup, the more usual usage of 'tar' is packing a directory, including its sub-directories and files: tar -cf foo.tar directory_name. So put your files into a directory before using tar is a good habit.
If you have installed gzip and bzip2 (almost all Unix/Linux include them), tar can call them directly to compress. i.e. create a '.tar.gz' or '.tar.bz2' file. The argument 'z' stands for 'gzip': tar -czf foo.tar.gz directory_name and 'j' means 'bzip2': tar -cjf foo.tar.bz2 directory_name. Since compression is a hard task for CPU, this will take more time. But it can save much disk space indeed.
Restoring
Restoring means extracting files from a tar file. To extract files into the current directory from a normal tar file (without compression), just use 'x' argument. For example: tar -xf foo.tar. If you want to extract to another directory, you need '-C' (uppercase) argument. For example, tar -xf foo.tar -C /opt/foo will put the files into /opt/foo directory (make sure you have enough permission to write /opt/foo).
If the tar file is compressed, you need know its format, gzip or bzip2. Usually you can know it through the file's suffix. To extract from '.tar.gz' file, use 'z' argument and to extract from '.tar.bz2', use 'j'. 'tar' will call gunzip or bunzip2 automatically.
tar -zxf foo.tar.gz
tar -jxf foo.tar.bz2
How to view a tar file?
For some reasons, you want to know what a tar file includes but you don't want to extract files from it. What you need is 't' argument. It will list the files and directories that a tar file contains:
tar -tzf foo.tar.gz
Some tricks
If the files you want to backup is too large or too many, it may take very long time. You can add '&' to make tar run in the background, so you can continue to do other work.
tar -czf foo.tar.gz foo &
If you like to print the file that tar is processing currently, you can use 'v' argument:
tar -xzvf foo.tar.gz
It will show a list of files on the screen.
Join Orkut
How to Backup Your Files Automatically (for Linux users)
In the two previous articles I introduced two common used utilities in Linux operating system, tar and cron. "tar" is used for creating archive files and "cron" is a time-based scheduling utility. In this article, I will combine "tar" with "cron" to solve the problem: how to backup your files automatically?
Some people think that "backing up" is a boring work. I agree with them. But when an accidence happens, the backup files is very important. So for lazy users, it would be better to let the computer do the boring work.
Have you remembered how to use "tar" to create an archive file?
Tips: tar -cf ... or tar -czf ... to create a compressed archive file.
The task is: Dobby (a Linux user) is a writer and all his documents are located in /home/dobby/documents. He wants to backup his documents to /mnt/disk2 every day. And the backup files' name should be "document_MM-DD-YYYY.tar.gz".
For example, if a backup file's name is "document_08_31_2008.tar.gz", that means it was created in August 31st, 2008.
However, the second problem is that it will generate lots of files. So he wants to delete the old backup files automatically.
Let's solve the problem step by step.
Step 1. You should get the current date. You can use "date" command to do it. The command is:
date '+%m-%d-%Y'
You can test it in the terminal window. The result may be "08-31-2008". Here '+%m-%d-%Y' is a format string. A format string's first character must be '+'. '%m' means the month in two-digits format, '%d' and '%Y' means 'date of month' and 'year' respectively.
Step 2. Combine "date" with "tar". Lets create an archive file using "date" and "tar". "date" is used for getting the current date, which is a part of the archive file name.
tar czf /mnt/disk2/documents_`date '+%m-%d-%Y'`.tar.gz /home/dobby/documents
You see that I put the "date" command into a pair of backslashes '`' which means using its result to replace itself. In this way we can construct the archive file name.
Step 3. Edit /etc/crontab to let "cron" execute the command on time. Use your favorite text editor to open /etc/crontab. Add this line:
0 15 * * * root tar czf /mnt/disk2/documents_`date '+%m-%d-%Y'`.tar.gz /home/dobby/documents
Save it and quit. "cron" will execute this command as root account at 15:00 every day. If you want "cron" to read its configure file immediately, you should restart cron:
/etc/init.d/cron restart (be sure you have enough permissions)
Otherwise, cron will know this task after you reboot the computer.
Step 4. Solve "how to delete old files automatically". To delete the old files, first you should know which files is old, and what the "old" means. For example, if a file was created in one week ago, we think it's "old". You can use "find" to find the old archive files and delete them.
find /mnt/disk2 -name 'document_*.tar.gz' -mtime -7 -delete
It means finding the files whose names match the pattern 'document_*.tar.gz' in /mnt/disk2 directory and they were last modified 7 days ago. Then delete them.
Now add the command to /etc/crontab, let "cron" execute this command at 15:30 everyday:
30 15 * * * root find /mnt/disk2 -name 'document_*.tar.gz' -mtime -7 -delete
All things done. From now on, I think Dobby won't hate "backing up" any more.
Join Orkut
Some people think that "backing up" is a boring work. I agree with them. But when an accidence happens, the backup files is very important. So for lazy users, it would be better to let the computer do the boring work.
Have you remembered how to use "tar" to create an archive file?
Tips: tar -cf
The task is: Dobby (a Linux user) is a writer and all his documents are located in /home/dobby/documents. He wants to backup his documents to /mnt/disk2 every day. And the backup files' name should be "document_MM-DD-YYYY.tar.gz".
For example, if a backup file's name is "document_08_31_2008.tar.gz", that means it was created in August 31st, 2008.
However, the second problem is that it will generate lots of files. So he wants to delete the old backup files automatically.
Let's solve the problem step by step.
Step 1. You should get the current date. You can use "date" command to do it. The command is:
date '+%m-%d-%Y'
You can test it in the terminal window. The result may be "08-31-2008". Here '+%m-%d-%Y' is a format string. A format string's first character must be '+'. '%m' means the month in two-digits format, '%d' and '%Y' means 'date of month' and 'year' respectively.
Step 2. Combine "date" with "tar". Lets create an archive file using "date" and "tar". "date" is used for getting the current date, which is a part of the archive file name.
tar czf /mnt/disk2/documents_`date '+%m-%d-%Y'`.tar.gz /home/dobby/documents
You see that I put the "date" command into a pair of backslashes '`' which means using its result to replace itself. In this way we can construct the archive file name.
Step 3. Edit /etc/crontab to let "cron" execute the command on time. Use your favorite text editor to open /etc/crontab. Add this line:
0 15 * * * root tar czf /mnt/disk2/documents_`date '+%m-%d-%Y'`.tar.gz /home/dobby/documents
Save it and quit. "cron" will execute this command as root account at 15:00 every day. If you want "cron" to read its configure file immediately, you should restart cron:
/etc/init.d/cron restart (be sure you have enough permissions)
Otherwise, cron will know this task after you reboot the computer.
Step 4. Solve "how to delete old files automatically". To delete the old files, first you should know which files is old, and what the "old" means. For example, if a file was created in one week ago, we think it's "old". You can use "find" to find the old archive files and delete them.
find /mnt/disk2 -name 'document_*.tar.gz' -mtime -7 -delete
It means finding the files whose names match the pattern 'document_*.tar.gz' in /mnt/disk2 directory and they were last modified 7 days ago. Then delete them.
Now add the command to /etc/crontab, let "cron" execute this command at 15:30 everyday:
30 15 * * * root find /mnt/disk2 -name 'document_*.tar.gz' -mtime -7 -delete
All things done. From now on, I think Dobby won't hate "backing up" any more.
Join Orkut
Backing Up Files with "rsync" (for Linux users)
* Home
* Backup How-To's
* Backup software
* Online backup
* Others
* Forum
* Contact
* About
* Recent posts
Home
Backing Up Files with "rsync" (for Linux users)
By Wang Jinbo - Posted on September 15th, 2008
Tagged:
* Backup How-tos
* linux
* rsync
"rsync" is a simple but powerful backup utility in Linux. Although the traditional archive tool "tar" can make a backup, "rsync" supports more functions, for example, saving the backup on a remote machine. For incremental backups, rsync provides a better method than "tar".
How to Use "rsync"
The basic usage is:
rsync -a src/ dest/
This command will copy all the files and directories in the "src" to the "dest" directory. In fact, it is equivalent to "cp -a src/ dest/". But if there has been many files in "dest" and there are only a few differences between "src" and "dest". "rsync" runs much faster. It makes "rsync" more suitable for creating incremental backups.
Notice: For most of software, the trailing slash after a directory name isn't important, but it is not for rsync. Let's see two example (suppose there is a file "foo" in the "src" directory):
rsync -a src dest
This will produce dest/src/foo. However, if I add the slash after the directories:
rsync -a src/ dest/
This will produce dest/foo. As you see, rsync doesn't care of the trailing slash after the destination directory. But it is different between "src" and "src/". So you must know about it.
Option: --delete
"rsync" can make a completely same backup from the source directory. However, if I used "rsync" before and just now I deleted a file from the source directory, "rsync -a src/ dest/" won't delete the file from the destination (backup) directory. The option "--delete" can solve the problem. For example:
rsync -a --delete src/ dest/
It will check all the files and directores in "dest" and if rsync finds a file or a directory in the "dest" which is not it the "src" directory, rsync will delete it. In this way, rsync keeps the "src" and the "dest" completely same.
Use "cron" to execute rsync on time
"cron" is a time-based utility for executing some commands automatically. It can run some programmes at a specific time. If you are lazy enough, you can add "rsync" into the cron configure file: /etc/crontab.
Use a text editor to open /etc/crontab and add the following line into it:
20 4 * * * root rsync -a --delete src/ dest/
When the time is 04:20, cron will run "rsync -a --delete src/ dest/" to make a backup and delete the unused files. By the way, "cron" is a very useful utility in Linux/Unix operating system. If you want to learn more, you can read its manual page.
Join Orkut
* Backup How-To's
* Backup software
* Online backup
* Others
* Forum
* Contact
* About
* Recent posts
Home
Backing Up Files with "rsync" (for Linux users)
By Wang Jinbo - Posted on September 15th, 2008
Tagged:
* Backup How-tos
* linux
* rsync
"rsync" is a simple but powerful backup utility in Linux. Although the traditional archive tool "tar" can make a backup, "rsync" supports more functions, for example, saving the backup on a remote machine. For incremental backups, rsync provides a better method than "tar".
How to Use "rsync"
The basic usage is:
rsync -a src/ dest/
This command will copy all the files and directories in the "src" to the "dest" directory. In fact, it is equivalent to "cp -a src/ dest/". But if there has been many files in "dest" and there are only a few differences between "src" and "dest". "rsync" runs much faster. It makes "rsync" more suitable for creating incremental backups.
Notice: For most of software, the trailing slash after a directory name isn't important, but it is not for rsync. Let's see two example (suppose there is a file "foo" in the "src" directory):
rsync -a src dest
This will produce dest/src/foo. However, if I add the slash after the directories:
rsync -a src/ dest/
This will produce dest/foo. As you see, rsync doesn't care of the trailing slash after the destination directory. But it is different between "src" and "src/". So you must know about it.
Option: --delete
"rsync" can make a completely same backup from the source directory. However, if I used "rsync" before and just now I deleted a file from the source directory, "rsync -a src/ dest/" won't delete the file from the destination (backup) directory. The option "--delete" can solve the problem. For example:
rsync -a --delete src/ dest/
It will check all the files and directores in "dest" and if rsync finds a file or a directory in the "dest" which is not it the "src" directory, rsync will delete it. In this way, rsync keeps the "src" and the "dest" completely same.
Use "cron" to execute rsync on time
"cron" is a time-based utility for executing some commands automatically. It can run some programmes at a specific time. If you are lazy enough, you can add "rsync" into the cron configure file: /etc/crontab.
Use a text editor to open /etc/crontab and add the following line into it:
20 4 * * * root rsync -a --delete src/ dest/
When the time is 04:20, cron will run "rsync -a --delete src/ dest/" to make a backup and delete the unused files. By the way, "cron" is a very useful utility in Linux/Unix operating system. If you want to learn more, you can read its manual page.
Join Orkut
Linux Backup: Hard Disk Clone with "dd"
Most of Windows users may know "Norton Ghost". Norton Ghost is a backup software for hard disks. It can backup a whole hard disk or a partition to an image file. Also, Norton Ghost can copy all the contents from a hard disk to another exactly. However, Norton Ghost is a Windows software, users on other operating system (such as Linux) can not enjoy its powerful function. Fortunately, most of Unix/Linux operating system provides a command line whose function is similar to Norton Ghost, it is called "dd".
In fact, "dd" is much powerful than Norton Ghost. You can use many arguments to control it. In this short article, we only concern on how to backup a whole hard disk or a partition.
Hard Disk Clone
Suppose you have a 40GB hard disk and a removable hard disk whose capacity is 60GB, and you want to backup all the files from the hard disk to the removable disk. With "dd", it is a very easy task. Again, suppose your hard disk's Unix device name is /dev/sda and the removable disk is /dev/sdb. The following command can copy all the content from /dev/sda to /dev/sdb:
dd if=/dev/sda of=/dev/sdb
Here, if=... sets the source and of=... sets the destination. "dd" doesn't care of the contents of the hard disk. It just reads bytes from /dev/sda and writes them into /dev/sdb. It doesn't know what are files. So, the hard disk file system and how many partitions it has are not important. For example, if /dev/sda is splitted into three partitions, the /dev/sdb will have the same partitions. i.e. "destination" is completely same with "source".
Notice: to execute "dd" you should login as "root" or switch to "root" using "su" command. And you must be careful, a small mistake may cause a serious problem!
Making a Hard Disk Image File
Most of time you don't want to make a complete duplication of your hard disk. You may prefer to creating an image file of the hard disk and save it in other storage devices. The following command will create an image file "disk1.img" in your user's directory from /dev/sda:
dd if=/dev/sda of=~/disk1.img
Since you have created an image file, you can compress it with "gzip" or "bzip2":
gzip disk1.img #generates disk1.img.gz or
bzip2 disk1.img #generates disk1.img.bz2
You can save much storage space with compression. But it will take very long time.
Partition Clone
Backing up a hard disk partition is much similar to backing up a whole hard disk. The reason is that Unix/Linux uses device name, such as /dev/sda1, /dev/sda5... to indicate the partitions. For example, if you want to create an image file from the first partition of /dev/sda, use "dd" like this:
dd if=/dev/sda1 of=~/disk2.img
Also, you can compress the image file:
gzip disk2.img
By the way, you can copy a partition to another partition completely, just set "of" to the partition's device name. For example:
dd if=/dev/sda1 of=/dev/sdb5
This command will copy all the contents from /dev/sda1 to /dev/sdb5. You must be sure that the capacity of /dev/sdb5 is larger than /dev/sda1.
Restoring from an Image File
To restore a partition or a hard disk from an image file, just exchange the arguments "if" and "of". For example, restore the whole hard disk from the image file "disk1.img":
dd if=disk1.img of=/dev/sda
Restore the first partition of /dev/sda from the image file "disk2.img":
dd if=disk2.img of=/dev/sda1
join Orkut
In fact, "dd" is much powerful than Norton Ghost. You can use many arguments to control it. In this short article, we only concern on how to backup a whole hard disk or a partition.
Hard Disk Clone
Suppose you have a 40GB hard disk and a removable hard disk whose capacity is 60GB, and you want to backup all the files from the hard disk to the removable disk. With "dd", it is a very easy task. Again, suppose your hard disk's Unix device name is /dev/sda and the removable disk is /dev/sdb. The following command can copy all the content from /dev/sda to /dev/sdb:
dd if=/dev/sda of=/dev/sdb
Here, if=... sets the source and of=... sets the destination. "dd" doesn't care of the contents of the hard disk. It just reads bytes from /dev/sda and writes them into /dev/sdb. It doesn't know what are files. So, the hard disk file system and how many partitions it has are not important. For example, if /dev/sda is splitted into three partitions, the /dev/sdb will have the same partitions. i.e. "destination" is completely same with "source".
Notice: to execute "dd" you should login as "root" or switch to "root" using "su" command. And you must be careful, a small mistake may cause a serious problem!
Making a Hard Disk Image File
Most of time you don't want to make a complete duplication of your hard disk. You may prefer to creating an image file of the hard disk and save it in other storage devices. The following command will create an image file "disk1.img" in your user's directory from /dev/sda:
dd if=/dev/sda of=~/disk1.img
Since you have created an image file, you can compress it with "gzip" or "bzip2":
gzip disk1.img #generates disk1.img.gz or
bzip2 disk1.img #generates disk1.img.bz2
You can save much storage space with compression. But it will take very long time.
Partition Clone
Backing up a hard disk partition is much similar to backing up a whole hard disk. The reason is that Unix/Linux uses device name, such as /dev/sda1, /dev/sda5... to indicate the partitions. For example, if you want to create an image file from the first partition of /dev/sda, use "dd" like this:
dd if=/dev/sda1 of=~/disk2.img
Also, you can compress the image file:
gzip disk2.img
By the way, you can copy a partition to another partition completely, just set "of" to the partition's device name. For example:
dd if=/dev/sda1 of=/dev/sdb5
This command will copy all the contents from /dev/sda1 to /dev/sdb5. You must be sure that the capacity of /dev/sdb5 is larger than /dev/sda1.
Restoring from an Image File
To restore a partition or a hard disk from an image file, just exchange the arguments "if" and "of". For example, restore the whole hard disk from the image file "disk1.img":
dd if=disk1.img of=/dev/sda
Restore the first partition of /dev/sda from the image file "disk2.img":
dd if=disk2.img of=/dev/sda1
join Orkut
Tuesday, January 25, 2011
Linux Commands
Command
Description
adduser Add a new user
arch Print machine architecture
awk Find and Replace text within file(s)
bc An arbitrary precision calculator language
cal Display a calendar
cat Concatenate files and print on the standard output
chdir Change working directory
chgrp Change the group ownership of files
chkconfig Tool for maintaining the /etc/rc[0-6].d directory hierarchy
chmod Change the access permissions of files and directories
chown Change the user and group ownership of files
chroot Change root directory
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
date Display or change the date & time
dc Desk Calculator
dd Data Dump – Convert and copy a file
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dir Briefly list directory contents
dircolors Colour setup for `ls’
dirname Convert a full pathname to just a path
du Estimate file space usage
echo Display message on screen
ed A line-oriented text editor (edlin)
egrep Search file(s) for lines that match an extended expression
eject Eject CD-ROM
env Display, set, or remove environment variables
expand Convert tabs to spaces
expr Evaluate expressions
factor Print prime factors
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fgrep Search file(s) for lines that match a fixed string
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width
format Format disks or tapes
free Display memory usage
fsck Filesystem consistency check and repair
gawk Find and Replace text within file(s)
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress named file(s)
head Output the first part of file(s)
hostname Print or set system name
id Print user and group id’s
info Help info
install Copy files and set attributes
join Join lines on a common field
kill Stop a process from running
less Display output one screen at a time
ln Make links between files
locate Find files
logname Print current login name
lpc Line printer control program
lpr Off line print
lprm Remove jobs from the print queue
ls List information about file(s)
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mv Move or rename files or directories
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
pr Convert text files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
pwd Print Working Directory
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
ram ram disk device
rcp Copy files between two machines
rm Remove files
rmdir Remove folder(s)
rpm Remote Package Manager
rsync Remote file copy (Synchronize file trees)
screen Terminal window manager
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
shutdown Shutdown or restart linux
sleep Delay for a specified time
sort Sort text files
split Split a file into fixed-size pieces
su Substitute user identity
sum Print a checksum for a file
symlink Make a new name for a file
sync Synchronize data on disk with memory
tac Concatenate and write files in reverse
tail Output the last part of files
tar Tape Archiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program Resource Use
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
umount Unmount a device
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unshar Unpack shell archive scripts
useradd Create new user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
vdir Verbosely list directory contents (`ls -l -b’)
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Report all known instances of a command
which Locate a program file in the user’s path
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un’)
xargs Execute utility, passing constructed argument list(s)
yes Print a string until interrupted
join orkut Community
http://www.orkut.co.in/Main#Community?cmm=110667357
Description
adduser Add a new user
arch Print machine architecture
awk Find and Replace text within file(s)
bc An arbitrary precision calculator language
cal Display a calendar
cat Concatenate files and print on the standard output
chdir Change working directory
chgrp Change the group ownership of files
chkconfig Tool for maintaining the /etc/rc[0-6].d directory hierarchy
chmod Change the access permissions of files and directories
chown Change the user and group ownership of files
chroot Change root directory
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
date Display or change the date & time
dc Desk Calculator
dd Data Dump – Convert and copy a file
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dir Briefly list directory contents
dircolors Colour setup for `ls’
dirname Convert a full pathname to just a path
du Estimate file space usage
echo Display message on screen
ed A line-oriented text editor (edlin)
egrep Search file(s) for lines that match an extended expression
eject Eject CD-ROM
env Display, set, or remove environment variables
expand Convert tabs to spaces
expr Evaluate expressions
factor Print prime factors
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fgrep Search file(s) for lines that match a fixed string
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width
format Format disks or tapes
free Display memory usage
fsck Filesystem consistency check and repair
gawk Find and Replace text within file(s)
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress named file(s)
head Output the first part of file(s)
hostname Print or set system name
id Print user and group id’s
info Help info
install Copy files and set attributes
join Join lines on a common field
kill Stop a process from running
less Display output one screen at a time
ln Make links between files
locate Find files
logname Print current login name
lpc Line printer control program
lpr Off line print
lprm Remove jobs from the print queue
ls List information about file(s)
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mv Move or rename files or directories
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
pr Convert text files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
pwd Print Working Directory
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
ram ram disk device
rcp Copy files between two machines
rm Remove files
rmdir Remove folder(s)
rpm Remote Package Manager
rsync Remote file copy (Synchronize file trees)
screen Terminal window manager
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
shutdown Shutdown or restart linux
sleep Delay for a specified time
sort Sort text files
split Split a file into fixed-size pieces
su Substitute user identity
sum Print a checksum for a file
symlink Make a new name for a file
sync Synchronize data on disk with memory
tac Concatenate and write files in reverse
tail Output the last part of files
tar Tape Archiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program Resource Use
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
umount Unmount a device
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unshar Unpack shell archive scripts
useradd Create new user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
vdir Verbosely list directory contents (`ls -l -b’)
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Report all known instances of a command
which Locate a program file in the user’s path
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un’)
xargs Execute utility, passing constructed argument list(s)
yes Print a string until interrupted
join orkut Community
http://www.orkut.co.in/Main#Community?cmm=110667357
Monday, January 24, 2011
Linux Commands for managing users:
Linux Commands for managing users:
* adduser(8) – Command used to add user accounts.
* chage (1) – Used to change the time the user’s password will expire.
* chfn(1) – Change a user’s finger information
* chsh(1) – Change a user’s shell.
* chgrp (1) – Changes the group ownership of files.
* chown (1) – Change the owner of file(s ) to another user.
* gpasswd (1) – Used to administer the /etc/group file.
* groupadd (8) – Create a new group.
* grpconv (8) – Creates /etc/gshadow from the file /etc/group which converts to shadow passwords.
* grpunconv (8)- Uses the files /etc/passwd and /etc/shadow to create /etc/passwd, then deletes /etc/shadow which converts from shadow passwords.
* groupdel (8) – Delete a group
* groupmod (8) – Modify a group
* groups (1) – print the groups a user is in
* grpck (8) – Verify the integrity of group files.
* id(1) – Print group or user ID numbers for the specified user.
* newgrp(1) – Allows a user to log in to a new group.
* newusers (8) – Update and create new users in batch form.
* nologin (5) – Prevent non-root users from logging onto the system.
* passwd (1) – Used to update a user’s password. The command “passwd username” will set the password for the given user.
* pwconv (8) – Used to create the file /etc/shadow from the file /etc/passwd to convert to shadow passwords.
* pwunconv (8) – Uses the files /etc/passwd and /etc/shadow to create /etc/passwd, then deletes /etc/shadow to convert from shadow passwords.
* su (1) – run a shell with substitute user and group IDs
* useradd (8) – Create a new user or update default new user information
* userdel (8) – Delete a user account and their files from the system. The command “userdel -r newuser” will remove the user and deletes their home directory.
* usermod (8) – Modify a user account.
Other useful commands/examples:
* find / -user username -ls :- Gives a list of all files owned by username.
* chown -R myuser /home/myuser :- Changes ownership of all files in mysuer home directory to myuser.
* chmod +s filename :- Sets the uid
Files :
* /etc/passwd – Where the user’s name, and other pertinent information are stored. This includes the password unless your system is using shadow passwords.
* /etc/shadow – Where the user’s password is stored if you are using shadow passwords.
* /etc/group – Where group names are stored.
* /etc/aliases – Where the user’s name is matched to a nickname for e-mail.
* /etc/sudoers – A list of users with special privileges along with the commands they can execute.
File Formats :
Note group ID numbers start at 100 and user ID numbers start at 500. The file /etc/group gives groups
The /etc/passwd file:
username:password:uid:gid:gecos:homedir:shell
Gecos contains information about the user, including the real name. Shell is the name and path of the user’s default shell program.
The /etc/group file:
groupname:password:gid:members
If the entry “bigclown:*: mark,george” is in the group file, the users mark and george are members of the bigclown group.
Examples :
To add a user, while logged in as root, type “adduser username”.
To set a user password, while logged in as root or the user that will be changed, type “passwd username”. If “passwd” is typed, the password will be changed for the user, you are logged in as.
To remove a user, while logged in as root, type “userdel -r username”. This will remove the user’s home directory. You can delete the user without the “-r” option and delete the user’s home directory manually. If the group the user was in, is no longer needed, you may delete it by editing the “/etc/group” file.
The file “/etc/aliases” is where the user’s real name is matched to their user name for e-mail accounts. Add users to this file in the form:
Firstname,Lastname:username
Then update the database by typing “newaliases”.
User Process Accounting :
Process accounting is supported by new kernels. To use this feature, you’ll need to get the acct-1.3.73.tar.gz package or later. The package contains some programs used to manage users. The following commands are useful for user accounting:
* ac(1) – Print statistics about users’ connect time.
* accton (8) – Turn on accounting of processes. To turn it on type “accton /var/log/pacct”.
* last(1) – Shows a list of users who have logged in.
* lastb(1) – Shows failed login attempts. This command requires the file /var/log/btmp to exist in order to work. Type “touch /var/log/btmp” to begin logging to this file.
* lastcomm (1) – Display information about previous commands in reverse order. Works only if process accounting is on.
* sa(8) – Generates a summary of information about users’ processes that are stored in the /var/log/pacct file.
* utmpdump(1) – Used for debugging.
* who(1) – Find out what users are logged onto the system.
Files that hold accounting information
* /var/log/wtmp – Stores information about all logins and logouts.
* /var/run/utmp – Stores information about who is currently on the system and is used by the who command.
* /var/log/btmp – Used to store information about failed logins.
The /var/log/wtmp file, contains the following information:
* Type of Login
* Process ID of login process
* The device name of the tty used
* The init ID or abbreviated ttyname
* User Name
* Hostname for remote login
* Exit Status of a process
* The session ID
* The time entry was made
* IP address of remote host
See the man page for wtmp(5) for more information.
The ability to set quotas limits a user’s disk storage by setting:
1. The number of inodes the user or group may use.
2. The number of disk blocks a user or group may use.
This limits user’s ability to use up all system resources. It only works on ext2 filesystems. Quotas must be set for each filesystem that the user may use. The kernel must have quota support compiled in.
User Quotas :
The ability to set quotas limits a user’s disk storage by setting:
1. The number of inodes the user or group may use.
2. The number of disk blocks a user or group may use.
This limits the user’s ability to use up all system resources. It only works on ext2 filesystems. Quotas must be set for each filesystem that the user may use. The kernel must have quota support compiled in.
Commands used to set quotas and limits are:
* edquota(8) – Used to edit user or group quotas. This program uses the vi editor to edit the quota.user and quota.group files. If the environment variable EDITOR is set to emacs, the emacs editor will be used. Type “export EDITOR=emacs” to set that variable.
* quota(1) – Display users’ limits and current disk usage.
* quotaoff(8) – Turns system quotas off.
* quotaon(8) – Turn system quotas on.
* quotacheck(8) – Used to check a filesystem for usage, and update the quota.user file.
* repquota(8) – Lists a summary of quota information on filesystems.
* ulimit – A bash builtin command for setting the processes a user can run. The command “ulimit -n 9000″ will set the limit on open files to 9000.
Files:
* /etc/mtab
* quota.user – Resides on the filesystem quotas are being set on.
* quota.group
Read the Quota mini howto for more information. Here’s roughly what is needed to enable and set quotas:
1. In your startup scripts, you should use the quotacheck and quotaon commands to start quota checking at system startup. Read the “How Linux Works” or the “Linux Startup Manual” for more information on startup scripts. This is already setup properly in most current versions of Linux.
2. In the /etc/fstab file, add the mount options “usrquota” and “grpquota”. You only need “grpquota” if you are going to set group quotas also. An example entry:
/dev/hda2 / ext2 defaults,usrquota,grpquota 1 1
3. Issue the following commands, where “fs” is the name of the filesystem where quotas are to be set. The first two commands create the quota files, and the second two commands keep users from accessing those files.
touch /fs/quota.user
touch /fs/quota.group
chmod 600 /fs/quota.user
chmod 600 /fs/quota.group
4. If you use emacs rather than vi to edit files, type “export EDITOR=emacs”. You may want to add this command to your shell startup script such as $HOME/.bash_profile.
5. Type “edquota username” to edit the quota file. You get a screen like this:
Quotas for user george:
/dev/hda2: blocks in use: 10672, limits (soft = 0, hard = 0)
inodes in use: 1856, limits (soft = 0, hard = 0)
/dev/hda3: blocks in use: 0, limits (soft = 0, hard = 0)
inodes in use: 0, limits (soft = 0, hard = 0)
Enter the limits you want to set and save the file. The soft limits are those that may be exceeded for limited periods of time, and the hard limits may not be exceeded.
Join Orkut Community
http://www.orkut.co.in/Main#Community?cmm=110667357
* adduser(8) – Command used to add user accounts.
* chage (1) – Used to change the time the user’s password will expire.
* chfn(1) – Change a user’s finger information
* chsh(1) – Change a user’s shell.
* chgrp (1) – Changes the group ownership of files.
* chown (1) – Change the owner of file(s ) to another user.
* gpasswd (1) – Used to administer the /etc/group file.
* groupadd (8) – Create a new group.
* grpconv (8) – Creates /etc/gshadow from the file /etc/group which converts to shadow passwords.
* grpunconv (8)- Uses the files /etc/passwd and /etc/shadow to create /etc/passwd, then deletes /etc/shadow which converts from shadow passwords.
* groupdel (8) – Delete a group
* groupmod (8) – Modify a group
* groups (1) – print the groups a user is in
* grpck (8) – Verify the integrity of group files.
* id(1) – Print group or user ID numbers for the specified user.
* newgrp(1) – Allows a user to log in to a new group.
* newusers (8) – Update and create new users in batch form.
* nologin (5) – Prevent non-root users from logging onto the system.
* passwd (1) – Used to update a user’s password. The command “passwd username” will set the password for the given user.
* pwconv (8) – Used to create the file /etc/shadow from the file /etc/passwd to convert to shadow passwords.
* pwunconv (8) – Uses the files /etc/passwd and /etc/shadow to create /etc/passwd, then deletes /etc/shadow to convert from shadow passwords.
* su (1) – run a shell with substitute user and group IDs
* useradd (8) – Create a new user or update default new user information
* userdel (8) – Delete a user account and their files from the system. The command “userdel -r newuser” will remove the user and deletes their home directory.
* usermod (8) – Modify a user account.
Other useful commands/examples:
* find / -user username -ls :- Gives a list of all files owned by username.
* chown -R myuser /home/myuser :- Changes ownership of all files in mysuer home directory to myuser.
* chmod +s filename :- Sets the uid
Files :
* /etc/passwd – Where the user’s name, and other pertinent information are stored. This includes the password unless your system is using shadow passwords.
* /etc/shadow – Where the user’s password is stored if you are using shadow passwords.
* /etc/group – Where group names are stored.
* /etc/aliases – Where the user’s name is matched to a nickname for e-mail.
* /etc/sudoers – A list of users with special privileges along with the commands they can execute.
File Formats :
Note group ID numbers start at 100 and user ID numbers start at 500. The file /etc/group gives groups
The /etc/passwd file:
username:password:uid:gid:gecos:homedir:shell
Gecos contains information about the user, including the real name. Shell is the name and path of the user’s default shell program.
The /etc/group file:
groupname:password:gid:members
If the entry “bigclown:*: mark,george” is in the group file, the users mark and george are members of the bigclown group.
Examples :
To add a user, while logged in as root, type “adduser username”.
To set a user password, while logged in as root or the user that will be changed, type “passwd username”. If “passwd” is typed, the password will be changed for the user, you are logged in as.
To remove a user, while logged in as root, type “userdel -r username”. This will remove the user’s home directory. You can delete the user without the “-r” option and delete the user’s home directory manually. If the group the user was in, is no longer needed, you may delete it by editing the “/etc/group” file.
The file “/etc/aliases” is where the user’s real name is matched to their user name for e-mail accounts. Add users to this file in the form:
Firstname,Lastname:username
Then update the database by typing “newaliases”.
User Process Accounting :
Process accounting is supported by new kernels. To use this feature, you’ll need to get the acct-1.3.73.tar.gz package or later. The package contains some programs used to manage users. The following commands are useful for user accounting:
* ac(1) – Print statistics about users’ connect time.
* accton (8) – Turn on accounting of processes. To turn it on type “accton /var/log/pacct”.
* last(1) – Shows a list of users who have logged in.
* lastb(1) – Shows failed login attempts. This command requires the file /var/log/btmp to exist in order to work. Type “touch /var/log/btmp” to begin logging to this file.
* lastcomm (1) – Display information about previous commands in reverse order. Works only if process accounting is on.
* sa(8) – Generates a summary of information about users’ processes that are stored in the /var/log/pacct file.
* utmpdump(1) – Used for debugging.
* who(1) – Find out what users are logged onto the system.
Files that hold accounting information
* /var/log/wtmp – Stores information about all logins and logouts.
* /var/run/utmp – Stores information about who is currently on the system and is used by the who command.
* /var/log/btmp – Used to store information about failed logins.
The /var/log/wtmp file, contains the following information:
* Type of Login
* Process ID of login process
* The device name of the tty used
* The init ID or abbreviated ttyname
* User Name
* Hostname for remote login
* Exit Status of a process
* The session ID
* The time entry was made
* IP address of remote host
See the man page for wtmp(5) for more information.
The ability to set quotas limits a user’s disk storage by setting:
1. The number of inodes the user or group may use.
2. The number of disk blocks a user or group may use.
This limits user’s ability to use up all system resources. It only works on ext2 filesystems. Quotas must be set for each filesystem that the user may use. The kernel must have quota support compiled in.
User Quotas :
The ability to set quotas limits a user’s disk storage by setting:
1. The number of inodes the user or group may use.
2. The number of disk blocks a user or group may use.
This limits the user’s ability to use up all system resources. It only works on ext2 filesystems. Quotas must be set for each filesystem that the user may use. The kernel must have quota support compiled in.
Commands used to set quotas and limits are:
* edquota(8) – Used to edit user or group quotas. This program uses the vi editor to edit the quota.user and quota.group files. If the environment variable EDITOR is set to emacs, the emacs editor will be used. Type “export EDITOR=emacs” to set that variable.
* quota(1) – Display users’ limits and current disk usage.
* quotaoff(8) – Turns system quotas off.
* quotaon(8) – Turn system quotas on.
* quotacheck(8) – Used to check a filesystem for usage, and update the quota.user file.
* repquota(8) – Lists a summary of quota information on filesystems.
* ulimit – A bash builtin command for setting the processes a user can run. The command “ulimit -n 9000″ will set the limit on open files to 9000.
Files:
* /etc/mtab
* quota.user – Resides on the filesystem quotas are being set on.
* quota.group
Read the Quota mini howto for more information. Here’s roughly what is needed to enable and set quotas:
1. In your startup scripts, you should use the quotacheck and quotaon commands to start quota checking at system startup. Read the “How Linux Works” or the “Linux Startup Manual” for more information on startup scripts. This is already setup properly in most current versions of Linux.
2. In the /etc/fstab file, add the mount options “usrquota” and “grpquota”. You only need “grpquota” if you are going to set group quotas also. An example entry:
/dev/hda2 / ext2 defaults,usrquota,grpquota 1 1
3. Issue the following commands, where “fs” is the name of the filesystem where quotas are to be set. The first two commands create the quota files, and the second two commands keep users from accessing those files.
touch /fs/quota.user
touch /fs/quota.group
chmod 600 /fs/quota.user
chmod 600 /fs/quota.group
4. If you use emacs rather than vi to edit files, type “export EDITOR=emacs”. You may want to add this command to your shell startup script such as $HOME/.bash_profile.
5. Type “edquota username” to edit the quota file. You get a screen like this:
Quotas for user george:
/dev/hda2: blocks in use: 10672, limits (soft = 0, hard = 0)
inodes in use: 1856, limits (soft = 0, hard = 0)
/dev/hda3: blocks in use: 0, limits (soft = 0, hard = 0)
inodes in use: 0, limits (soft = 0, hard = 0)
Enter the limits you want to set and save the file. The soft limits are those that may be exceeded for limited periods of time, and the hard limits may not be exceeded.
Join Orkut Community
http://www.orkut.co.in/Main#Community?cmm=110667357
Subscribe to:
Posts (Atom)