<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ayush Bhat</title>
    <description>The latest articles on DEV Community by Ayush Bhat (@ayush11_bhat).</description>
    <link>https://dev.to/ayush11_bhat</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F705137%2F18bda845-921c-47f8-bf7c-75fca6904345.jpeg</url>
      <title>DEV Community: Ayush Bhat</title>
      <link>https://dev.to/ayush11_bhat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ayush11_bhat"/>
    <language>en</language>
    <item>
      <title>Management in Linux </title>
      <dc:creator>Ayush Bhat</dc:creator>
      <pubDate>Sun, 17 Oct 2021 10:45:13 +0000</pubDate>
      <link>https://dev.to/ayush11_bhat/management-in-linux-1743</link>
      <guid>https://dev.to/ayush11_bhat/management-in-linux-1743</guid>
      <description>&lt;p&gt;In this blog we will be exploring the following fields in Linux:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;User Account Management&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Group Management&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;File Permissions And Ownership&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Let's start with User Account Management
&lt;/h2&gt;

&lt;p&gt;Question arises why to have different user accounts? To answer this following are some points that we keep in mind.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Each user will have their own individualized private space.&lt;/li&gt;
&lt;li&gt;Will help in distinguishing privileges among users.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note : &lt;strong&gt;root&lt;/strong&gt; user is a special user who is able to do anything on the system.&lt;/p&gt;

&lt;h4&gt;
  
  
  Attributes Of a User
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;UID : It is a unique number that is assigned to the user account. It is also used for determination of user privileges and activity tracking.&lt;/li&gt;
&lt;li&gt;GID : Indicates default group of the user.&lt;/li&gt;
&lt;li&gt;Comment : Using comment field for contact information.&lt;/li&gt;
&lt;li&gt;Home Directory : This is owned by a user and will be found on system under &lt;strong&gt;/home&lt;/strong&gt; directory, except for root.&lt;/li&gt;
&lt;li&gt;Login Shell : Various shells are there e.g. /bin/bash or /bin/csh.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Create user accounts
&lt;/h4&gt;

&lt;p&gt;WHAT actually happens behind the scene when a user account is created let's debug it 😎&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;strong&gt;/etc/login.defs&lt;/strong&gt; ; the next UID greater than UID_MIN by default is assigned to the new user.&lt;/li&gt;
&lt;li&gt;By default value of UID is assigned to GID.&lt;/li&gt;
&lt;li&gt;Then the home directory for the user is created.&lt;/li&gt;
&lt;li&gt;A login shell is attached with the user.&lt;/li&gt;
&lt;li&gt;The contents of &lt;strong&gt;/etc/skel&lt;/strong&gt; is copied to home directory of user. &lt;strong&gt;Note&lt;/strong&gt; : /etc/skel contains the startup files for bash and for the X Window system.&lt;/li&gt;
&lt;li&gt;Command to create a user named &lt;strong&gt;student&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useradd -s /bin/bash -m  student
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Deleting and Modifying User Account
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;userdel&lt;/strong&gt; : The root user can remove user accounts using this command. This command doesn't delete the home directory. To delete the home directory use &lt;strong&gt;-r&lt;/strong&gt; option. User reference is removed from &lt;strong&gt;/etc/passwd, /etc/shadow, and /etc/group&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;usermod&lt;/strong&gt; : Change the characteristics of a user account, such as group memberships, home directory, login, name, password, default shell, user id etc.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Locked Accounts
&lt;/h4&gt;

&lt;p&gt;You might be thinking what is locked accounts? To answer this in Linux some accounts are locked means they can run programs but can never login to the system and have no valid password associated with them, such as bin and daemon.&lt;br&gt;
If you look up these entries in the &lt;strong&gt;/etc/passwd&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To lock a user account&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;usermod -L student
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Unlocking can be done by -U option.&lt;/p&gt;

&lt;h4&gt;
  
  
  User ID's and /etc/passwd
&lt;/h4&gt;

&lt;p&gt;If we look up in some entries of /etc/passwd we will see the following records. Each record consists of a number of fields separated by colons (:):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;student:x:1006:1008::/home/student:/bin/bash
user1:x:1002:1002:user 1:/home/user1:/bin/bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;username : user's unique name &lt;/li&gt;
&lt;li&gt;password : it can be hashed password or a placeholder ("x")&lt;/li&gt;
&lt;li&gt;UID : User Identification Number&lt;/li&gt;
&lt;li&gt;GID : primary group identification number for the user&lt;/li&gt;
&lt;li&gt;comment : comment area, usually the user's real name&lt;/li&gt;
&lt;li&gt;home : user's home drectory&lt;/li&gt;
&lt;li&gt;shell : name of the shell to be invoked at the login&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Why to use /etc/shadow when /etc/passwd is available?
&lt;/h5&gt;

&lt;p&gt;The default permissions in /etc/passwd is &lt;em&gt;644 (-rw-r--r--)&lt;/em&gt;&lt;em&gt;, this make the file vulnerable to attack as anyone can read this file. Tools like Crack, John the ripper can easily exploit this file. &lt;br&gt;
*&lt;/em&gt;/etc/shadow** : provides greater security of hashed passwords, also provides the option of enabling password aging on a per user basis. The permission attached to this file **400 (-r--------), means only root can access this file. Let's see one record from this file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;student:$6$2BDjRtz3.i4hg.bY$/KxesQ.UefXY3dUpvnWf0L6oi24TaPONhqHQgm9g/9IunYY1w2x0jNbuUNuRuvjTcx1Hjk0VUTnjDPKJjqBS51:18917:0:99999:7:::
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file contains one record for each user.&lt;br&gt;
Colon separated fields are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;username&lt;/li&gt;
&lt;li&gt;password (hashed 512)&lt;/li&gt;
&lt;li&gt;last change : days since Jan 1,1970 that password was last changed.&lt;/li&gt;
&lt;li&gt;mindays : minimum days after which password must be changed.&lt;/li&gt;
&lt;li&gt;maxdays : maximum days after which password must be changed.&lt;/li&gt;
&lt;li&gt;warn : days before password expires that the user is warned.&lt;/li&gt;
&lt;li&gt;grace : days after password expires that account is disabled.&lt;/li&gt;
&lt;li&gt;expire : date that account will be disabled.&lt;/li&gt;
&lt;li&gt;reserved &lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  Password Management
&lt;/h5&gt;

&lt;p&gt;&lt;strong&gt;passwd&lt;/strong&gt; is the command to change the password. Remember, Normal users can change only their own password. Root can change any user password. Normal users will not be allowed to set bad passwords, such as short words. However, root is allowed to do so.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@ayush:~# passwd student
New password:
Retype new password:
passwd: password updated successfully
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Group Management
&lt;/h4&gt;

&lt;p&gt;Linux Systems form collection of users called groups, whose member share some common purpose. They share certain files and directories, and maintain some common privileges; this separates them from others on the system called the world. Groups are defined in &lt;strong&gt;/etc/group&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat /etc/group
student:x:1008:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;where &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;groupname is name of the group&lt;/li&gt;
&lt;li&gt;password is password placeholder&lt;/li&gt;
&lt;li&gt;GID is the group identifier. Values between 0 and 99 are for system groups. Values between 100 and GID_MIN are considered special. Values over GID_MIN are for User Private Groups. Each user will have his or her own group, not guaranteed to be private, this is called UPG(User Private Groups).&lt;/li&gt;
&lt;li&gt;user1, user2 is the list of users who are the members of the group.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  Group Management
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;groupadd: Add a new group.&lt;/li&gt;
&lt;li&gt;groupmod: Modify a group and add new users.&lt;/li&gt;
&lt;li&gt;groupdel: Remove a group.&lt;/li&gt;
&lt;li&gt;usermod: Manage a user's group memberships.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's see the demo of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Step 1 - Create a group
   groupadd -r -g 245 student_grp
2. Step 2 - Add users in the group
   usermod -G  student_grp student
   usermod -G  student_grp user1
3. Check whether the group is created or not
   root@ayush:~# cat /etc/group | grep student_grp
   student_grp:x:245:student,user1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; : Be careful while using &lt;strong&gt;usermod -G&lt;/strong&gt; as grouplist that follows is complete list of groups, not just the changes, any supplemented groups left out will be gone !&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;-a option in usermod will preserve pre-existing group memberships when adding new ones.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Linux User has 1 primary group listed in /etc/passwd and /etc/group. Primary group GID is used whenever the user creates the files or directories.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Group membership can be identified by running the following command:
root@ayush:~# groups
root
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  File Permissions and Ownership
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;First character indicates the type of the file object. There are nine more which indicate the access rights granted to file users.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;root@ayush:~# ls -l file.txt
-rw-r--r--. 1 root root 16 Oct  8 12:31 file.txt 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;These are arranged in three groups of three:

&lt;ul&gt;
&lt;li&gt;owner: the user who owns the file&lt;/li&gt;
&lt;li&gt;group: the group of users who have access&lt;/li&gt;
&lt;li&gt;other: the rest of the world (also called world)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;File access rights
r : read access is allowed
w : write access is allowed
x : execute access is allowed &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If permission is not allowed a, - (dash) appears.&lt;/p&gt;

&lt;h5&gt;
  
  
  Want to change file permissions - Use chmod
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;Changing file permissions is done with chmod&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's see a demo now.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a file, give the owner and world execute permission, and remove the group write permission:
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O9wJpHOl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1dos1hsax21nhdt0gsb2.PNG" alt="Image description"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;You can only change permissions on files you own, unless you are the supervisor.&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;student user tried to change the file permissions but failed as this file is owned by other user.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cquui4zO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x53run4tovb1kpc14urt.PNG" alt="Image description"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Octal Digits&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple algorithm, and a single digit suffices to specify all three permissions bits for each entity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Octal Number representation&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Octal Number representation is sum of each digit of:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;4&lt;/strong&gt; - if read permission is desired&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;2&lt;/strong&gt; - if write permission is desired&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1&lt;/strong&gt; - if execute permission is desired&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Chown and Chgrp&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changing file ownership is done with &lt;strong&gt;chown&lt;/strong&gt; and changing the group is done with &lt;strong&gt;chgrp&lt;/strong&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt; : Only Superuser can change ownership on files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In this demo we have changed the owner of file from &lt;strong&gt;ayush&lt;/strong&gt; to &lt;strong&gt;user1&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SxhVxXYM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/85hpczw2cahalgbue5rx.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SxhVxXYM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/85hpczw2cahalgbue5rx.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In this demo we have changed the group ownership. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6_83Ov0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gl0hkeyr9ljc43ifmyfk.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6_83Ov0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gl0hkeyr9ljc43ifmyfk.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Umask&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Default permission given when creating a file are read/write for owner, group and world (0666) and for directory is (0777)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;But we noticed that actual permission on file is 664(u=rw, g=rw, o=r)  and for directory is 775(u=rwx, g=rwx, o=wx)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KDsEcC7p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0zknbl8acg9vztzpbsd.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KDsEcC7p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x0zknbl8acg9vztzpbsd.PNG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Question arises who has done it ? Umask is the answer.
Umask whose purpose is to show permissions should be denied.
Let's see the value of umask set by default.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;umask
0002
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This represents that for the other users write permission is disabled.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;That's all for now. Thank you for reading. Do share your feedback and if you have liked the article share it with your friends.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>linux</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
