Thursday 3 November 2011

Configuration of FTP Server in LINUX

Ftp server is designed for uploading and downloading the files, when ftp server users log's in, they get their home folder at client side and if public/anonymous user log's in they get data stored in /var/ftp folder

Steps to Configure FTP Server in LINUX

Step:--1.  Check and install required Packages

Check the packages are installed or not by rpm/yum command

[root@server ~]# rpm -q vsftpd

Remove the packages and old data if required

[root@server ~]# yum remove vsftpd* -y

Install the Packages

Note: Here my file is at Desktop. So i was changing the path to Desktop.

[root@server ~]# cd /root/Desktop/
[root@server Desktop]# ls

FileZilla3  tomcat  vsftpd-2.0.5-10.el5.i386.rpm

[root@server Desktop]# chmod 777 vsftpd-2.0.5-10.el5.i386.rpm

[root@server Desktop]# rpm -ivh vsftpd-2.0.5-10.el5.i386.rpm
warning: vsftpd-2.0.5-10.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing...                ########################################### [100%]
   1:vsftpd                 ########################################### [100%]

Step:--2. Create the resources on ftp server (file/folder & Users)

   Create users and assign passwords to whom you want to allow logging through ftp
  
   [root@server ~]# useradd tom
   [root@server ~]# useradd joy
   [root@server ~]# passwd tom
   Changing password for user tom.
   New UNIX password:
   BAD PASSWORD: it is too simplistic/systematic
   Retype new UNIX password:
   passwd: all authentication tokens updated successfully.
   [root@server ~]# passwd joy
   Changing password for user joy.
   New UNIX password:
   BAD PASSWORD: it is too simplistic/systematic
   Retype new UNIX password:
   passwd: all authentication tokens updated successfully.
   [root@server ~]#

Create or Copy some files inside /var/ftp/pub folder

[root@server ~]# cd /var/ftp/pub/
[root@server pub]# touch fa.txt fb.txt music.mp3
[root@server pub]# ls
fa.txt  fb.txt  music.mp3


Create a Upload folder for anonymous users and give full permission for read/write.

For example LINUX N UNIX HELP UPLOADS

[root@server pub]# mkdir /var/ftp/linux n unix help uploads
[root@server pub]# chmod 777 /var/ftp/linux n unix help uploads
[root@server pub]#


Step:--3. Edit the Main Configuration file /etc/vsftpd/vsftpd.conf

[root@server ~]# vi /etc/vsftpd/vsftpd.conf

  12 anonymous_enable=YES
 
  15 local_enable=YES

  27 anon_upload_enable=YES

  83 ftpd_banner=Welcome to LINUX N UNIX HELP

 
  :wq!
 
 
Step:--  4. To block the ftp server users (for Ex:-- joy) write the user name in file
 
  /etc/vsftpd/ftpusers
 
  [root@server ~]# vi /etc/vsftpd/ftpusers


# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody
joy
~
~
~
~
~
~
~
:wq!


Step:--5. start th ftp service


[root@server ~]# vi /etc/vsftpd/ftpusers
[root@server ~]# service vsftpd restart
Shutting down vsftpd:                                      [FAILED]
Starting vsftpd for vsftpd:                                [  OK  ]
[root@server ~]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[root@server ~]#



Note:--- Your system Firewall should be turnoff or In firewall settings ftp exception should be added.

For Checking your ftp in Client Machine, Do the following steps:

1.Open the Web Browser and give following URL

ftp://192.168.10.121/

Here replace your ftp server IP address.

To upload or Any changes use any Ftp Software like Winscp or Filzilla , etc....


Wednesday 2 November 2011

Network Configurations in Linux

Assigning a static IP address --- temporarily

Syntax:--

[root@server ~]# ifconfig <devicename> <IP address>

Example:-- To Assign the static IP address as 192.168.10.121

[root@server ~]# ifconfig eth0 192.168.10.121

To check the IP assigned

[root@server ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:08:02:F7:33:6A
          inet addr:192.168.10.121  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::208:2ff:fef7:336a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:773 errors:0 dropped:0 overruns:0 frame:0
          TX packets:137 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:77098 (75.2 KiB)  TX bytes:23592 (23.0 KiB)
          Interrupt:177

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1670 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1670 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3349244 (3.1 MiB)  TX bytes:3349244 (3.1 MiB)

Set Permanent IP address

Do the following Steps:

1. Go to the following Path

    [root@server ~]# cd /etc/sysconfig/network-scripts/

2. After that edit the following file

   [root@server network-scripts]# vi ifcfg-eth0
  
# Broadcom Corporation NetXtreme BCM5702X Gigabit Ethernet
DEVICE=eth0
HWADDR=00:08:02:f7:33:6a
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.10.121
GATEWAY=192.168.10.254
TYPE=Ethernet
~
~
:wq!

3. After this restart the network service to activate the new IP address.

To see the LAN card i.e NIC card Parameters


[root@server ~]# ethtool eth0
Settings for eth0:
        Supported ports: [ MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: g
        Wake-on: d
        Current message level: 0x000000ff (255)
        Link detected: yes

To enable IP address

[root@server ~]# ifup eth0

To disable IP address

[root@server ~]# ifdown eth0


This is a file where IP address are stored.

[root@server ~]# cd /etc/sysconfig/network-scripts/
[root@server network-scripts]# cat ifcfg-eth0
# Broadcom Corporation NetXtreme BCM5702X Gigabit Ethernet
DEVICE=eth0
HWADDR=00:08:02:f7:33:6a
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.10.121
GATEWAY=192.168.10.254
TYPE=Ethernet

Tuesday 1 November 2011

Networking in LINUX

Introduction to Networking in Linux

To check the system hostname

[root@localhost ~]# hostname
localhost.localdomain

Assigning the hostname - temporarly

Syntax:-

[root@localhost ~]# hostname <computer>

EX:- To assign the hostname as server.linuxnunixhelp.com

[root@localhost ~]# hostname server.linuxnunixhelp.com

To check the hostname assigned

[root@localhost ~]# hostname
server.linuxnunixhelp.com

Assigning hostname ---- Permanently

Edit the configuration file /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=server.linuxnunixhelp.com




:wq!

System Process Commands in Linux

TO check the Process id of any application, command etc

[root@localhost ~]# ps -aux

To kill a process normally


[root@localhost ~]# kill <process_id>

ex: -- [root@localhost ~]# kill 2521

To kill the process forcefully use stamp value as '9'
[root@localhost ~]# kill -9 <process_id>

[root@localhost ~]# kill -9 2521

To see the cpu & process status
[root@localhost ~]# top

To see the open port number and service name

[root@localhost ~]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 127.0.0.1:2208              0.0.0.0:*                   LISTEN      1802/hpiod
tcp        0      0 0.0.0.0:969                 0.0.0.0:*                   LISTEN      1635/rpc.statd
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1606/portmap
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1819/cupsd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1854/sendmail: acce
tcp        0      0 127.0.0.1:2207              0.0.0.0:*                   LISTEN      1807/python
tcp        0      0 :::22                       :::*                        LISTEN      1833/sshd
tcp        0    148 ::ffff:192.168.10.120:22    ::ffff:192.168.10.114:1401  ESTABLISHED 2411/1


To view how long the system is running

[root@localhost ~]# uptime
 23:34:45 up 23 min,  2 users,  load average: 0.00, 0.02, 0.08

To view Process, Resource and File Systems

[root@localhost ~]# gnome-system-monitor &


To dump the traffic on the network

[root@localhost ~]# tcpdump -i eth0


To display or change Ethernet card settings
[root@localhost ~]# ethtool eth0
Settings for eth0:
        Supported ports: [ MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Supports auto-negotiation: Yes
        Advertised link modes:  10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                1000baseT/Half 1000baseT/Full
        Advertised auto-negotiation: Yes
        Speed: 100Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 1

To Recover Root Password in Linux

1. Restart the PC while restarting press any key to get Grub Screen
2. Press 'e'
3. Select kernal /vmlinuz-2.6.18.-8.el5 ro root=LABEL=/ rhgb quiet
4. Again Press 'e' to edit
5. Edit kernal /vmlinuz-2.6.18.-8.el5 ro root=/ rhgb quiet line and erase quite and type single
6. Press enter
7. Press b to boot
8. At shell prompt type the commands

sh-3.00# passwd
Changing Password for user root
New UNIX Password:123456
Retype new UNIX Password: 123456
Passwd: all authentication tokens updated Successfully.

Now type the following command to Restart the system to the normal Login

sh-3.00# init 6

Usage of chkconfig command

To view the status of the the services in all runlevels
 

[root@localhost ~]# chkconfig --list

To view the status of the Particular services.
For example Bluetooth



[root@localhost ~]# chkconfig --list bluetooth
bluetooth       0:off   1:off   2:off   3:off   4:off   5:off   6:off

To put the service at all runlevel as on

[root@localhost ~]# chkconfig bluetooth on

To view the status

[root@localhost ~]# chkconfig --list bluetooth
bluetooth       0:off   1:off   2:on    3:on    4:on    5:on    6:off

To put the service at all runlevel as off


[root@localhost ~]# chkconfig bluetooth off

To view the status

[root@localhost ~]# chkconfig --list bluetooth
bluetooth       0:off   1:off   2:off   3:off   4:off   5:off   6:off


To manually stop the service

[root@localhost ~]# service bluetooth stop
Stopping Bluetooth services:                               [  OK  ]

To Manually start the service

[root@localhost ~]# service bluetooth start
Starting Bluetooth services:                               [  OK  ]


To Manually restart the service

[root@localhost ~]# service bluetooth restart
Stopping Bluetooth services:                               [  OK  ]
Starting Bluetooth services:                               [  OK  ]


Monday 31 October 2011

Boot Process in Linux

To View the default runlevel while booting the Linux Operating System
[root@tsmservertest ~]# vi /etc/inittab

id:5:initdefault:  (End of the line in Fedora OS)

Note: It means that OS by default always boot to GUI mode.


To View the current runlevel

[root@tsmservertest ~]# runlevel
N 5


To Switch to another runlevel and check the runlevl
[root@tsmservertest ~]# init 3
[root@tsmservertest ~]# runlevel
5 3

[root@tsmservertest ~]# init 2
[root@tsmservertest ~]# runlevel
3 2


[root@tsmservertest ~]# init 1
[root@tsmservertest ~]# runlevel
1 S


[root@tsmservertest ~]# init 6


To View the grup configuration file


[root@localhost ~]# cat /boot/grub/grub.conf

Saturday 22 October 2011

Backup and Recovery

Create a folder
for EX:-- /myfolder

[root@tsmservertest ~]# mkdir /myfolder
[root@tsmservertest ~]# cd /myfolder/

Now create Some files and folders inside it.

[root@tsmservertest myfolder]# mkdir dir1
[root@tsmservertest myfolder]# touch 1 songs tom_file
[root@tsmservertest myfolder]# ls
1  dir1  songs  tom_file


Use the tar command to tape archive the folder

[root@tsmservertest ~]# tar -cvf /opt/myfolder.tar /myfolder
tar: Removing leading `/' from member names
/myfolder/
/myfolder/tom_file
/myfolder/dir1/
/myfolder/songs
/myfolder/1

[root@tsmservertest ~]# cd /opt/
[root@tsmservertest opt]# ls -l
total 12
-rw-r--r-- 1 root root 10240 Oct 22 13:01 myfolder.tar


To Create a tar file with zip

[root@tsmservertest opt]# cd
[root@tsmservertest ~]# tar -cvzf /opt/myfolder.tar.gz /myfolder/
#########OUTPUT#############
tar: Removing leading `/' from member names
/myfolder/
/myfolder/tom_file
/myfolder/dir1/
/myfolder/songs
/myfolder/1
[root@tsmservertest ~]# cd /opt/
[root@tsmservertest opt]# ls -l
total 16
-rw-r--r-- 1 root root 10240 Oct 22 13:01 myfolder.tar
-rw-r--r-- 1 root root   194 Oct 22 13:10 myfolder.tar.gz


To View the contents of the tar file without extracting

[root@tsmservertest opt]# tar -tvzf /opt/myfolder.tar.gz
drwxr-xr-x root/root         0 2011-10-22 12:58 myfolder/
-rw-r--r-- root/root         0 2011-10-22 12:58 myfolder/tom_file
drwxr-xr-x root/root         0 2011-10-22 12:58 myfolder/dir1/
-rw-r--r-- root/root         0 2011-10-22 12:58 myfolder/songs
-rw-r--r-- root/root         0 2011-10-22 12:58 myfolder/1

To remove the folder

[root@tsmservertest ~]# rm -r /myfolder/
rm: descend into directory `/myfolder'? y
rm: remove regular empty file `/myfolder/tom_file'? y
rm: remove directory `/myfolder/dir1'? y
rm: remove regular empty file `/myfolder/songs'? y
rm: remove regular empty file `/myfolder/1'? y
rm: remove directory `/myfolder'? y
[root@tsmservertest ~]# cd /


To extract the tar file or recovery the data


[root@tsmservertest /]# tar -xvzf /opt/myfolder.tar.gz
myfolder/
myfolder/tom_file
myfolder/dir1/
myfolder/songs
myfolder/1


After extracting see the contents inside the folder


[root@tsmservertest /]# ls /myfolder/
1  dir1  songs  tom_file




Friday 9 September 2011

Disk Quotas in Linux

1. Create 4 users as below

          a. Ravi with the default properties
          b. Sunil whose primary group is sales
          c. Tom whose primary group is sales
          d. Rani whose secondary group is sales
2. Create a partition and mount it with users and group quotas enabled.
3. Apply quotas to the user Ravi and the group sales and check.

Create a Group

Example:- To create a group called as sales

 [root@test119 ~]# groupadd sales

Create the Users

Example:- Create users and add some to sales group

[root@test119 ~]# useradd ravi
[root@test119 ~]# useradd -g sales sunil
[root@test119 ~]# useradd -g sales tom
[root@test119 ~]# useradd -G sales tom
[root@test119 ~]# useradd -G sales rani


Create Partition using fdisk

Command:-

[root@test119 ~]# fdisk /dev/sda

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
Command (m for help): p

Disk /dev/sda: 40.0 GB, 40016019456 bytes
255 heads, 63 sectors/track, 4865 cylinders, total 78156288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xae04ae04

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    20678655     8241152   83  Linux
/dev/sda3        20678656    31016959     5169152   83  Linux
/dev/sda4        31016960    78155775    23569408    5  Extended
/dev/sda5        31021056    41357311     5168128   83  Linux
/dev/sda6        41359360    47798271     3219456   82  Linux swap / Solaris
/dev/sda7        47800320    54042623     3121152   83  Linux
/dev/sda8        54044672    58238975     2097152   83  Linux

Command (m for help): n
First sector (31019008-78155775, default 31019008): +100M
Value out of range.
First sector (31019008-78155775, default 31019008):
Using default value 31019008
Last sector, +sectors or +size{K,M,G} (31019008-31021055, default 31021055):
Using default value 31021055
 
Check if the new  Partition has been created

[root@test119 ~]# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 40.0 GB, 40016019456 bytes
255 heads, 63 sectors/track, 4865 cylinders, total 78156288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xae04ae04

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    20678655     8241152   83  Linux
/dev/sda3        20678656    31016959     5169152   83  Linux
/dev/sda4        31016960    78155775    23569408    5  Extended
/dev/sda5        31021056    41357311     5168128   83  Linux
/dev/sda6        41359360    47798271     3219456   82  Linux swap / Solaris
/dev/sda7        47800320    54042623     3121152   83  Linux
/dev/sda8        54044672    58238975     2097152   83  Linux
/dev/sda9        31019008    31021055        1024   83  Linux

Partition table entries are not in disk order

Note:- Here i dont have free space in My Hard Disk. So i was took default space.

Saving the Partitions

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource                                              busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)

To update the kernal without restarting the system

Command:

[root@test119 ~]# partprobe /dev/sda


Format the Partition in Linux

[root@test119 ~]# mkfs.ext3 /dev/sda9

Mounting the Partition with user and group quotas enabled

Syntax:

mount <option> <arguments> <partition name> <mount poin dir>

Example:- To Mount the 9th Partition on a directory /mntpoint with user and group quotas enabled

[root@test119 ~]# mkdir /mntpoint
[root@test119 ~]# mount -o usrquota,grpquota /dev/sda9 /mntpoint/

To view mounted partitions

command:-

[root@test119 ~]# mount
/dev/sda8 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda3 on /home type ext4 (rw)
/dev/sda5 on /opt type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda7 on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sda9 on /mntpoint type ext2 (rw,usrquota,grpquota)


Apply full permissions on the mount point


Example:-


[root@test119 ~]# chmod 777 /mntpoint


Create the quota database files


Syntax:-

[root@localhost~]# quotacheck <options> <mount point>


Options:
-c create                           -g -- group
-u -- user                          -v -- verbose

Example:-

[root@test119 ~]# quotacheck -cugv /mntpoint/

Check if the quota database file aquota.group and aquota.user has been created

[root@test119 ~]# ls /mntpoint/
aquota.group  aquota.user  lost+found

Check the quota status

Syntax:- 

[root@localhost~]# quotaon <options> <partition>

Example:

[root@test119 ~]# quotaon -p /dev/sda9
group quota on /mntpoint (/dev/sda9) is off
user quota on /mntpoint (/dev/sda9) is off

Turn on Quotas:

[root@test119 ~]# quotaon /dev/sda9

To check the status

[root@test119 ~]# quotaon -p /dev/sda9
group quota on /mntpoint (/dev/sda9) is on
user quota on /mntpoint (/dev/sda9) is on

Apply Quota for the users:

Example:- User ravi can create 5 files or directories after which he gets  a warning message and he should not be allowed to create more than 7 files or directories

[root@test119 ~]# edquota -u ravi

Disk quotas for user ravi (uid 502):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sda9                         0           0          0          0              5        7

:wq!

To check

Example:

[root@test119 ~]# su - ravi
[ravi@test119 ~]$ cd /mntpoint/
[ravi@test119 mntpoint]$ touch file1 file2 file3 file4 file5
[ravi@test119 mntpoint]$ touch file6
[ravi@test119 mntpoint]$ touch file7
[ravi@test119 mntpoint]$ touch file8
touch: cannot touch `file8': Disk quota exceeded

[ravi@test119 mntpoint]$ ls
aquota.group  aquota.user  file1  file2  file3  file4  file5  file6  file7  lost+found





Sunday 28 August 2011

Permissions in Linux

Create three users:

Example:

[root@test119 ~]# useradd kavita
[root@test119 ~]# useradd ramu
[root@test119 ~]# useradd srinu

Make ramu the member of the group kavita

Example:
[root@test119 ~]# gpasswd -a ramu kavita
Adding user ramu to group kavita


Create a directory


Example:

[root@test119 ~]# mkdir /linux

Check the default permission of the above created directory

[root@test119 ~]# ls -ld /linux/
drwxr-xr-x 2 root root 4096 Aug 28 11:26 /linux/

Give full permissions to the above created directory

Example using absolute mode

[root@test119 ~]# chmod 777 /linux/
                         (or)
Example using symbolic mode

[root@test119 ~]# chmod ugo=rwx /linux/

Check the permissions on the directory


[root@test119 ~]# ls -ld /linux/
drwxrwxrwx 2 root root 4096 Aug 28 11:26 /linux/

Log in as the user kavita

Example:

[root@localhost~]# su -kavita

As user kavita create a file inside the above created directory

-sh-4.1$ cd /linux/
-sh-4.1$ ls
-sh-4.1$
-sh-4.1$ cat >fedora
This is a version of linux operating system
ctrl+D

Check the permisson on the file


Example: 

-sh-4.1$ ls -l
total 4
-rw-r--r-- 1 kavita kavita 44 Aug 28 11:41 fedora

Explaination

1. The user kavita has Read and Write permission on this file
2. The group kavitha has read and write permisson on this file (as ramu is a member of the group kavita he     will also have rad and write permisson).
3. Others will have read only permisson ( as srinu belong to others he will have only read permisson).


To check the permissons


Example:- As kavita try to read and add some content to the file

-sh-4.1$ cat fedora
This is a version of linux operating system
-sh-4.1$ cat >> fedora
This line has been added by kavita
-sh-4.1$ cat fedora
This is a version of linux operating system
This line has been added by kavita

Example:- As ramu try to read and add some content to the file ( open another terminal and do the following)

-sh-4.1$ su - ramu
Password:
-sh-4.1$ cd /linux/
-sh-4.1$ ls
fedora
-sh-4.1$ cat fedora
This is a version of linux operating system
This line has been added by kavita
-sh-4.1$ cat >> fedora
This line has been added by ramu

Example:- As srinu to read and add some content to the file (Open another terminal and do the following)

[root@test119 ~]# su - srinu
-sh-4.1$ cd /linux/
-sh-4.1$ ls
fedora
-sh-4.1$ cat fedora
cat: fedora: Permission denied

Change the permisson on the above file


Example:- Remove write permission for the group kavita

-sh-4.1$ cd /linux/
-sh-4.1$ ls
fedora
-sh-4.1$ chmod g=r fedora
-sh-4.1$ ls -l
total 4
--w-r---w- 1 kavita kavita 106 Aug 28 12:04 fedora


Check the permisson on the above file


Example:- As ramu try to read and add some content to the file

-sh-4.1$ su - ramu
Password:
-sh-4.1$ whoami
ramu
-sh-4.1$
-sh-4.1$ cd /linux/
-sh-4.1$ ls
fedora
-sh-4.1$ cat fedora
This is a version of linux operating system
This line has been added by kavita
This line is added by ramu
-sh-4.1$ cat >> fedora
-sh: fedora: Permission denied

Change the permisson on the above file


Example:- Give write permission for others

-sh-4.1$ su - kavita
Password:
-sh-4.1$ cd /linux/
-sh-4.1$ ls
fedora
-sh-4.1$ chmod 646 fedora
-sh-4.1$ ls -l
total 4
-rw-r--rw- 1 kavita kavita 106 Aug 28 12:04 fedora

check the permisson on the above file

Example:- As srinu try to read and add some content to the file

[root@test119 ~]# su - srinu
-sh-4.1$ cd /linux/
-sh-4.1$ ls
fedora
-sh-4.1$ cat fedora
This is a version of linux operating system
This line has been added by kavita
This line is added by ramu
-sh-4.1$ cat >> fedora
This line has been added by srinu
-sh-4.1$ cat fedora
This is a version of linux operating system
This line has been added by kavita
This line is added by ramu
This line has been added by srinu

Friday 26 August 2011

Group Membership in Linux

Syntax:- 

[root@localhost~]# gpasswd <option> <arguments> <groupname>

Options:

-M -- Add multiple users to a group
-A -- Add a group Administrator
-a -- Add a single user to a group
-d -- Delete a user from a group


Example:- Add multiple users (ravi, sunil) to the group marketing
Note: Before doing this the group marketing should be exists.

[root@test119 ~]# gpasswd -M ravi,sunil marketing

To check if the users are added to the group

[root@test119 ~]# grep marketing /etc/group

marketing:x:2006:ravi,sunil


Example:- Add user rani as the administrator for the group marketing

[root@test119 ~]# useradd rani
[root@test119 ~]# gpasswd -A rani marketing

To check if rani has been added as the administrator for the group marketing

[root@test119 ~]# grep marketing /etc/gshadow
marketing:!:rani:ravi,sunil


Example:- Add a user ahmed to the group marketing

[root@test119 ~]# useradd ahmed
[root@test119 ~]# gpasswd -a ahmed marketing
Adding user ahmed to group marketing

To check if the user has been added to the group

[root@test119 ~]# grep marketing /etc/group
marketing:x:2006:ravi,sunil,ahmed


Example:- Delete the user ravi from the group marketing

[root@test119 ~]# gpasswd -d ravi marketing
Removing user ravi from group marketing

To check if the user has been deleted from the group

[root@test119 ~]# grep marketing /etc/group
marketing:x:2006:sunil,ahmed

Creating a user along with it Group Membership

Example:- Creating a user sri with primary group as hr and member of the group finance

[root@test119 ~]# groupadd hr
[root@test119 ~]# groupadd finance
[root@test119 ~]# useradd -g hr -G finance sri

To check if the user has been created along with group membership

[root@test119 ~]# grep sri /etc/passwd /etc/group
/etc/passwd:sri:x:2008:2009::/home/sri:/bin/sh
/etc/group:finance:x:2010:sri

Adding or Modifying or Deleting users and groups using a graphical tool

Open the graphical too using command


[root@test119 ~]# system-config-users &


Group Administration in Linux

Creating a Group

Syntax:- 

[root@localhost~]# groupadd <groupname>

                          (or)

[root@localhost~]# groupadd <option> <argument> <groupname>

Options:

-g -- Group ID
-0 -- Override


Example:- Creating a group Sales with default options

[root@test119 ~]# groupadd sales


To check if the group has been created

[root@test119 ~]# tail -5 /etc/group

avdefs:x:504:
ali:x:2001:
tom:x:2002:
anu:x:2003:
sales:x:2004:


Example:- Creating a group mktg whose group id (GID) is 750

[root@test119 ~]# groupadd -g 750 mktg

To check if the group has been created

[root@test119 ~]# tail -5 /etc/group

ali:x:2001:
tom:x:2002:
anu:x:2003:
sales:x:2004:
mktg:x:750:


Modifying the Properties of a Group


Syntax:-

[root@localhost~]# groupadd <option> <argument> <groupname>

Options:

-g -- Group ID
-o -- Override
-n -- Group Name


Example:- Change the GID of the group sale to 800

[root@test119 ~]# groupmod -g 800 sale

To check if the group ID has changed

[root@test119 ~]# tail -5 /etc/group

tom:x:2002:
anu:x:2003:
sales:x:2004:
mktg:x:750:
sale:x:800:

Deleting a group

Syntax:-

[root@localhost~]# groupdel <groupname>

Example:- Delete the group sale

[root@test119 ~]# groupdel sale


To check if the group has been deleted

[root@test119 ~]# tail -5 /etc/group ali:x:2001:
tom:x:2002:
anu:x:2003:
sales:x:801:
mktg:x:750:


Thursday 25 August 2011

Creating an User

Syntax :-


[roort@localhost~]# useradd <username>

or

[roort@localhost~]# useradd <option> <argument> <username>

Options:

-u -- UID                                                        -c -- comment

-g -- Primary Group Name or GID                  -d -- Home directory

-o -- Override                                                 -s -- Shell

-G -- Secondary Group

Example :- Creating a user ravi with defalut options

[root@test119 ~]# useradd ravi

To check if the  user has been created

[root@test119 ~]# tail -5 /etc/passwd

gdm:x:42:42::/var/lib/gdm:/sbin/nologin
Ganesh:x:500:500:Ganesh Tulagapu:/home/Ganesh:/bin/bash
ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh



Example :- Creating a user ali whose user id (UID) is 2001


[root@test119 ~]# useradd -u 2001 ali

To check if the user has been created

[root@test119 ~]# tail -5 /etc/passwd

Ganesh:x:500:500:Ganesh Tulagapu:/home/Ganesh:/bin/bash
ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh


Example :- Creating a user tom with a comment 'Manager'


[root@test119 ~]# useradd -c Manager tom


To check if the user has been created

[root@test119 ~]# tail -5 /etc/passwd

ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
tom:x:2002:2002:Manager:/home/tom:/bin/sh

Example :- Creating a user anu whose home directory is inside /'salesdept'

Note: Before creating a user in salesdept, you should create a directory as /salesdept

[root@test119 ~]# useradd -d /salesdept/anu anu

To check if the user has been created

 [root@test119 ~]# tail -5 /etc/passwd

admin:x:503:503::/home/admin:/bin/sh
ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
tom:x:2002:2002:Manager:/home/tom:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh

Example :- Creating a user Jack whose shell is 'c shell'

[root@test119 ~]# useradd -s /bin/csh Jack


To check if user has been created with 'c shell'


[root@test119 ~]# tail -5 /etc/passwd

ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
tom:x:2002:2002:Manager:/home/tom:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
Jack:x:2004:2004::/home/Jack:/bin/csh


Example :- Change the login name of user tom to jill


[root@test119 ~]# usermod -l jill tom

To check if the user has been Modified

[root@test119 ~]# tail -5 /etc/passwd

ravi:x:504:505::/home/ravi:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
Jack:x:2004:2004::/home/Jack:/bin/csh
jill:x:2002:2002:Manager:/home/tom:/bin/sh


To delete a user

Syntax :- 

[root@localhost~]# userdel <option> <username>


Options:

-r -- Recursively (along with the home directory and mailbox)

Example :- Deleting the user ravi

[root@test119 ~]# userdel ravi

To check if the user has been deleted

ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
Jack:x:2004:2004::/home/Jack:/bin/csh
jill:x:2002:2002:Manager:/home/tom:/bin/sh

[root@test119 ~]# ls /home/
admin  ali  Ganesh  Jack  lost+found  ram  rama  ravi  tera  tom


Example :- Deleting the user Jack along his home directory and mail box
[root@test119 ~]# userdel -r Jack


To check if the user has been deleted

[root@test119 ~]# tail -6 /etc/passwd

Ganesh:x:500:500:Ganesh Tulagapu:/home/Ganesh:/bin/bash
ram:x:501:501:ramakrishna:/home/ram:/bin/bash
admin:x:503:503::/home/admin:/bin/sh
ali:x:2001:2001::/home/ali:/bin/sh
anu:x:2003:2003::/salesdept/anu:/bin/sh
jill:x:2002:2002:Manager:/home/tom:/bin/sh

[root@test119 ~]# ls /home/
admin  ali  Ganesh  lost+found  ram  rama  ravi  tera  tom

To view the details of a user from all database files

Example:- To view the details of a user anu

[root@test119 ~]# grep anu /etc/passwd /etc/shadow
/etc/passwd:anu:x:2003:2003::/salesdept/anu:/bin/sh
/etc/shadow:anu:!!:15211:0:99999:7:::


To view the UID and GID of a user

Example:- To view the details of a user Anu

[root@test119 ~]# id anu
uid=2003(anu) gid=2003(anu) groups=2003(anu)


To Change the Password Parameters

Syntax:-

[root@localhost~]# chage <username>

Example:- To change the Password Parameters for the User Jill

[root@test119 ~]# chage jill

Changing the aging information for jill
Enter the new value, or press ENTER for the default

        Minimum Password Age [0]: 1
        Maximum Password Age [99999]: 10
        Last Password Change (YYYY-MM-DD) [2011-08-25]:
        Password Expiration Warning [7]: 4
        Password Inactive [-1]:
        Account Expiration Date (YYYY-MM-DD) [1969-12-31]:


To check do the following steps:

1. Log off Root
2. Log in as Jill
3. Try changing the Password
4. Log off as Jill
5. Log in as Root
6. Change the system date to two days ahead
7. Log off as Root
8. Login as Jill
9. Try changing the Password

Wednesday 24 August 2011

Basic Commands - 2.1

To View the calender

Example : To see the current month

[root@localhost ~] # cal

     August 2011  
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

Example : -   TO see the past, current and next month

[root@localhost ~] # cal -3
 
     July 2011            August 2011         September 2011 
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
                1  2      1  2  3  4  5  6               1  2  3
 3  4  5  6  7  8  9   7  8  9 10 11 12 13   4  5  6  7  8  9 10
10 11 12 13 14 15 16  14 15 16 17 18 19 20  11 12 13 14 15 16 17
17 18 19 20 21 22 23  21 22 23 24 25 26 27  18 19 20 21 22 23 24
24 25 26 27 28 29 30  28 29 30 31           25 26 27 28 29 30 
31                                                             

Example :- To see the calender of the current year

[root@localhost ~] # cal -y

Example: To see the calender for the month of December for the year 2010

[root@localhost ~] # cal 12 2010

Example: To see the calender for the full year 2009

[root@localhost ~] # cal 2009

To View help for a command (manual Pages)


Syntax :-


[root@localhost ~] # man <command>


To See the help for the command mkdir

[root@localhost ~] # man mkdir

To View the top 10 lines of a file

Example :- 

[root@localhost ~] # head anaconda-ks.cfg

To View the top 5 lines of a file

Example :-


[root@localhost ~] # head -5 anaconda-ks.cfg

To view the bottom 10 lines of a file

Example :-

[root@localhost ~] # tail anaconda-ks.cfg

To view the bottom 3 lines of a file

Example :-

[root@localhost ~] # tail -3 anaconda-ks.cfg

Basic Commands - 2.0

Copying files and Directories

[root@localhost ~]# cp <option> <source> <destination>


Example :- To copy a file

[root@localhost ~]# cp completereport /opt

To check if the file has been copied

[root@localhost ~]# cd /opt

[root@localhost ~]# ls

completereport


Example :- To copy a directory

[root@localhost ~]# cp -r directory1/ /opt/

To check if the directory has been copied

[root@localhost ~]# cd /opt

[root@localhost ~]# ls

completereport directory1

Moving files and directories

Syntax :-

[root@localhost ~]# mv <option> <source> <destination>


Example :- To Move a file

[root@localhost ~]# salesreport /opt

To check if the file has been moved


completereport directory1 salesreport


Example :- To move a directory

[root@localhost ~]# mv dir1 /opt


To check if the directory has been moved

[root@localhost ~]# cd /opt

[root@localhost ~]# ls

completereport directory1 dir1 salesreport

Renaming files and directories

Syntax :- 

[root@localhost ~]# mv <old name> <new name>

Example :- To rename a file

[root@localhost ~]# mv completereport fullreport


To check if the file has been Renamed

[root@localhost ~]# ls

anaconda-ks.cfg  file1       install.log         savap-install.log
Desktop          file2       install.log.syslog  sav-install.log
directory1       file3       mktgreport          savjlu-install.log
directory2       file4       POOL.log            savui-install.log
directory3       fullreport  POOL.logpid
directory4       glassfish3  salesreport

Deleting an empty directory

Syntax :- 

 [root@localhost ~]# rmdir <directory name>

Example :- To delete an empty directory

[root@localhost ~]# rmdir directory2

To check if the directory has been deleted
anaconda-ks.cfg  file2        install.log.syslog  sav-install.log
Desktop          file3        mktgreport          savjlu-install.log
directory1       file4        POOL.log            savui-install.log
directory3       fullreport   POOL.logpid
directory4       glassfish3   salesreport
file1            install.log  savap-install.log

Deleting a file or directory

Syntax :-

 [root@localhost ~]# rm <option> <file or directory>

Options :

-r -- recursive
-f -- forcefully

Example :- To delete a file

[root@localhost ~]# rm file4

rm: remove regular empty file `file4'? y


To check if the file has been deleted

[root@localhost ~]# ls

anaconda-ks.cfg  file1       install.log         salesreport
Desktop          file2       install.log.syslog  savap-install.log
directory1       file3       mktgreport          sav-install.log
directory3       fullreport  POOL.log            savjlu-install.log
directory4       glassfish3  POOL.logpid         savui-install.log

To delete a file forcefully

[root@localhost ~]# rm -f mktgreport

To check if the file has been deleted

[root@localhost ~]# ls
anaconda-ks.cfg  file1       install.log         savap-install.log
Desktop          file2       install.log.syslog  sav-install.log
directory1       file3       POOL.log            savjlu-install.log
directory3       fullreport  POOL.logpid         savui-install.log
directory4       glassfish3  salesreport

Example :- To delete a directory

[root@localhost ~]# cd /opt

 [root@localhost ~]# rm -rf dir1


To check if the directory has been deleted

[root@localhost ~]# ls

completereport directory1 salesreport

To view the system date and time

[root@localhost ~]# date

Wed Aug 24 20:34:34 IST 2011

To change the system date and time

Syntax :-

[root@localhost ~]# date -s "MM/DD/YYYY hh:mm:ss"

Example:

[root@localhost ~]#date -s "07/15/2009 00:06:00"

Wed Jul 15 00:06:00 IST 2009

Monday 22 August 2011

Creating Directories & Directory Navigation

Syntax :-

[root@localhost~]# mkdir <option> <directory name>

Example :- Creating a single directory

[root@localhost~]# mkdir directory1

Example :- Creating multiple directories

[root@localhost~]# mkdir direcoty2 directory3 directory4

To check if the directories have been created

[root@localhost~]# ls -d directory*

directory1  directory2  directory3  directory4

Example :- To create nested directories (Sub directories inside directories)

[root@localhost~]# mkdir -p d1/d2/d3/d4

To check if the nested directories have been created

[root@localhost~]# ls -R d1

/d1:
d2

/d1/d2:
d3

/d1/d2/d3:
d4

/d1/d2/d3/d4:

Note :- To list the contents and create a file or directory in a location different from the present working directory, Specify the complete path (example /var/directory1)

Directory Navigation

Syntax :-

[root@localhost~]# cd <argument>

Example :- To go into a directory

[root@localhost~]# cd d1

[root@localhost d1]# cd d2

 [root@localhost d2]#

Example :- To back one level, type cd press spacebar then dot dot

[root@localhost d2]# cd ..

[root@localhost d1]#

Example :- To go back two levels

[root@localhost d1]# cd ../..

[root@localhost /]#

Example :- To go to the Previous working directory 

[root@localhost /]# cd -

/root/d1

Example :- To go to current logged in user's home directory

[root@localhost d1]#cd

[root@localhost ~]# pwd

/root

Basic Commands -1.2

Creating files and adding data using cat command

Syntax :-

[root@localhost~]# cat <option> <arguments>

Example :- To create a file along with some data

[root@localhost~]# cat > salesreport

This file contains the sales report for the month Aug.

( Now press Ctrl+d to Save )

Example :- To create one more  file along with some data

[root@localhost~]# cat > mktgreport

This file contains the mktg report for the month of Aug.


( Now press Ctrl+d to Save )



Example :- To read the contents of a file

[root@localhost~]# cat salesreport

This file contains the sales report for the month of Aug.

Example : - To append (add) to a file

[root@localhost~]# cat >> mktgreport

This year the efforts in mktg have increased.

Ctrl+D

Check the contents of the file mktgreport

[root@localhost~]# cat mktgreport

This file contains the mktg report for the month of Aug
This year the efforts in mktg have increased.


Example :- To merge contents of two files into a third file

[root@localhost~]# cat salesreport mktgreport >> completereport

Check the contents of the file Completereport

[root@localhost~]# cat completereport

This file contains the sales report for the month of Aug.
This file contains the mktg report for the month of Aug.
This year the efforts in mktg have increased.

Creating 0 byte (empty) files using touch command

 Syntax :- Creating a single file with the touch command 

 [root@localhost~]# touch <filename>

Example :- Creating a single file with touch command

[root@localhost~]# touch file1

To check if the file has been created

 [root@localhost~]# ls -ld file1

-rw-r--r--. 1 root root 0 Aug 23 09:13 file1

Example :- Creating multiple file using the touch command

[root@localhost~]# touch file2 file3 file4

To check if the file has been created

 [root@localhost~]# ls -ld file*

-rw-r--r--. 1 root root 0 Aug 23 09:13 file1
-rw-r--r--. 1 root root 0 Aug 23 09:16 file2
-rw-r--r--. 1 root root 0 Aug 23 09:16 file3
-rw-r--r--. 1 root root 0 Aug 23 09:16 file4

To change the timestamp (date and time of modification) of a file or directory

Syntax :-

 [root@localhost~]# touch <option> <arguments> <file or directory name>

Example :- To change to the current date and time

[root@localhost~]# touch file1

To check if the timestamp has changed

[root@localhost~]# ls -ld file1

-rw-r--r--. 1 root root 0 Aug 23 09:20 file1

Syntax :-

[root@localhost~]#  touch -t YYYYMMDDHHMM <file or directory name>

Example :- To change to a different date and time

[root@localhost~]# touch -t 200905150842 file2

To check if the timestamp has changed

[root@localhost~]# ls -ld file2

-rw-r--r--. 1 root root 0 May 15  2009 file2


Sunday 21 August 2011

Basic Commands -1.1

To check the Present working directory

Syntax :-
[root@localhost`]# pwd

Example :-
[root@localhost~]# pwd
/root


To See the contents of a directory (folder)


Syntax :-
[root@localhost~]# ls <option> <argument>

Options:

-l          Long list including attributes
 -a         All files and directories including hidden
-d         To check for a particular file or directory
-R        Recursively, to see the contents in a tree structure


Example :- To list the contents of the present working Directory



[root@localhost~]# ls
 anaconda-ks.cfg    install.log.syslog  POOL.logpid
Desktop          install.log  POOL.log
Example :- To see the list of files and directories along with their attributes (Properties)

[root@localhost~]# ls -l
 total 96
-rw-------. 1 root root  1280 Jul  3 00:46 anaconda-ks.cfg
drwxr-xr-x. 2 root root  4096 Jul 15 14:47 Desktop
drwxr-xr-x. 2 root root  4096 Jul 15 16:38 glassfish3
-rw-r--r--. 1 root root 56509 Jul  3 00:46 install.log
-rw-r--r--. 1 root root 12953 Jul  3 00:44 install.log.syslog
-rw-r--r--. 1 root root   822 Aug 16 11:22 POOL.log
-rw-r--r--. 1 root root    32 Aug 16 11:22 POOL.logpid

Example :- To see all files and directories including hidden files of files and directories

[root@localhost~]# ls -a
.                .bash_profile  .gconfd             .lesshst     .tcshrc
..               .bashrc        glassfish3          .macromedia  .updatetool
anaconda-ks.cfg  .config        .gnome2             .nbi         .viminfo
.asadminpass     .cshrc         install.log         POOL.log     .xauthsjBb2W
.bash_history    Desktop        install.log.syslog  POOL.logpid
.bash_logout     .gconf         .java               .ssh


Example :- To check if a perticular file or directory is present

[root@localhost~]# ls -d Desktop
Desktop

Example :- To see tree structure of nested directories

[root@localhost~]# ls -R
/opt:
galaxy
/opt/galaxy:
galaxya
/opt/galaxy/galaxya:
galaxyb
/opt/galaxy/galaxya/galaxyb:
galaxys
/opt/galaxy/galaxya/galaxyb/galaxys:

Example :- To see a list of all file or directories starting with a perticular letter

[root@localhost~]# ls i*
install.log  install.log.syslog

Example :-  To see the attributes of a perticular file or directory

[root@localhost~]# ls -ld install.log.syslog
 -rw-r--r--. 1 root root 12953 Jul  3 00:44 install.log.syslog

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews