Add the Linux groups to your server:
[firstname.lastname@example.org tmp]# groupadd parents
[email@example.com tmp]# groupadd children
[firstname.lastname@example.org tmp]# groupadd soho
Add the Linux users and assign them to their respective groups
email@example.com tmp]# useradd -g parents ram
[firstname.lastname@example.org tmp]# useradd -g parents jagmohan
[email@example.com tmp]# useradd -g children ramesh
[firstname.lastname@example.org tmp]# useradd -g children hema
[email@example.com tmp]# useradd -g soho accounts
[firstname.lastname@example.org tmp]# useradd -g soho sales
User root changing the password for user ram
[email@example.com root]# passwd ram
Changing password for user ram.
Retype new password:
passwd: all authentication tokens updated successfully.
There is also an optional -r switch that additionally removes all the contents of the user’s home directory.
# userdel -r ram
How to Tell the Groups to Which a User Belongs
[firstname.lastname@example.org root]# groups ram
ram : parents
How to Change the Ownership of a File
[email@example.com tmp]# ll test.txt
-rw-r–r– 1 root root 0 Nov 17 22:14 test.txt
[firstname.lastname@example.org tmp]# chown testuser:users test.txt
[email@example.com tmp]# ll test.txt
-rw-r–r– 1 testuser users 0 Nov 17 22:14 test.txt
Temporarily Gaining root Privileges
[firstname.lastname@example.org bob]$ more /etc/sudoers
/etc/sudoers: Permission denied
Bob tries again using sudo and his regular user password and is successful:
[email@example.com bob]$ sudo more /etc/sudoers
Becoming root for a Complete Login Session
The su command allows a regular user to become the system’s root user if they know the root password. A user with sudo rights to use the su command can become root, but they only need to know their own password, not that of root as seen here.
firstname.lastname@example.org:~$ sudo su –
The /etc/sudoers file contains all the configuration and permission parameters needed for sudo to work.
Granting All Access to Specific Users
You can grant users bob and bunny full access to all privileged commands, with this sudoers entry.
bob, bunny ALL=(ALL) ALL
This is generally not a good idea because this allows bob and bunny to use the su command to grant themselves permanent root privileges thereby bypassing the command logging features of sudo. The example on using aliases in the sudoers file shows how to eliminate this prob
Granting Access To Specific Users To Specific Files
This entry allows user peter and all the members of the group operator to gain access to all the program files in the /sbin and /usr/sbin directories, plus the privilege of running the command /usr/local/apps/check.pl. Notice how the trailing slash (/) is required to specify a directory location:
peter, %operator ALL= /sbin/, /usr/sbin, /usr/local/apps/check.pl
Granting Access to Specific Files as Another User
The sudo -u entry allows allows you to execute a command as if you were another user, but first you have to be granted this privilege in the sudoers file.
This feature can be convenient for programmers who sometimes need to kill processes related to projects they are working on. For example, programmer peter is on the team developing a financial package that runs a program called monthend as user accounts. From time to time the application fails, requiring “peter” to stop it with the /bin/kill, /usr/bin/kill or /usr/bin/pkill commands but only as user “accounts”. The sudoers entry would look like this:
peter ALL=(accounts) /bin/kill, /usr/bin/kill, /usr/bin/pkill
User peter is allowed to stop the monthend process with this command:
[email@example.com peter]# sudo -u accounts pkill monthend
Granting Access Without Needing Passwords
This example allows all users in the group operator to execute all the commands in the /sbin directory without the need for entering a password. This has the added advantage of being more convenient to the user:
%operator ALL= NOPASSWD: /sbin/
To create a Tar file
tar -czf archive.tar.gz *.txt
To list files in a compressed Tar file
tar -tzf archive.tar.gz.