File Ownership in Linux Ubunto
File Ownership in Linux/Ubunto
This Lecture teaches you the following topics:
- Changing ownership of a file
- Creating a user/group account using CLI
- Deleting user/group account using CLI
Changing Ownership and Group
- Changing the ownership of a file/directory
For changing the ownership of a file/directory, you can use the following command:
chown user filename/directoryname
- Changing the both group and user owner of a file/directory
In case you want to change the user as well as group for a file or directory use the command
chown user:group filename
- Changing the group owner of a file/directory
In case you want to change group-owner only, use the command
chgrp group_name filename
‘chgrp’ stands for change group.
- To Check groups
The file /etc/group contains all the groups defined in the system
cat /etc/group
- Find all the groups, a user belongs
You can use the command “groups” to find all the groups you are a member of
- To Change the default group
You can use the command newgrp to work as a member a group other than your default group.
The default group in our example is computer:
After changing the default group to adm:
Creating a User Account using the Command Line
To create a new user account using the Command line, follow the below steps:
- Hit Ctrl+Alt+Tto launch the command line Terminal application in Ubuntu.
- Now in order to create a new user account, use adduser command as follows:
sudo adduser <username>
- Replace <username>with your new user account name that you want to create.
Creating a new group
To create a new group, we use the command groupadd.
sudo groupadd groupname
For Example:
sudo groupadd editorial
Adding users to group
usermod command is used to add a new user to a group.
sudo usermod -a -G editorial Rehan
-a option tells usermod we are appending.
-G option tells usermod we are appending to the group name that follows the option.
grep editorial /etc/group
The above command will search the group editorial in group file.
Deleting the User Account
deluser command is use to delete a user account. To delete the user account using the command line, use the following syntax:
sudo deluser <username>
Deleting the Group
sudo delgroup groupname