#Day5 #90DaysOfDevOps

Index

Task solution

Few Important command

User Management commands in Linux

Task Solution

Task 1: If you noticed that there are total 90 sub directories in the directory '2023' of this repository. What did you think, how did I create 90 directories. Manually one by one or using a script, or a command ?

All 90 directories within seconds using a simple command.

mkdir day{1..90}

Tasks You have to do the same using Shell Script i.e using either Loops or command with start day and end day variables using arguments

image

make sure you provide permission to execute this file.

I used "chmod 700 filename"

image

Task 2: Create a Script to backup all your work done till now.

image

make sure you provide permission to execute this file.

image

Task 3: Read About Cron and Crontab, to automate the backup Script

image

image

Task 4: Read about User Management and Let me know on Linkedin if you're ready for Day 6.

User management in Linux refers to the process of creating, modifying, and managing user accounts and permissions on a Linux system. It is an essential aspect of system administration and plays a crucial role in maintaining the security, access control, and overall stability of the Linux environment. From a DevOps point of view, user management is important for several reasons:

->Access Control: In a DevOps environment, multiple team members collaborate on various projects. User management allows administrators to grant appropriate access privileges to team members, ensuring that each user has the necessary permissions to perform their tasks without compromising security.

->Security: Proper user management helps enforce the principle of least privilege, where users only have access to the resources they require for their roles. By setting up user accounts with the right permissions, the risk of unauthorized access to critical system files and data is reduced.

->Auditing and Accountability: User management enables tracking user activities and actions on the system. It helps identify who performed specific actions, making it easier to troubleshoot issues, investigate security breaches, and maintain accountability within the DevOps team.

->Isolation: Creating separate user accounts for different users helps isolate their processes and activities from each other. This isolation ensures that one user's actions or errors do not adversely affect others or the system as a whole.

->Automated Deployments: In DevOps, automation plays a significant role in deploying applications and managing infrastructure. Proper user management allows DevOps tools and scripts to authenticate and execute actions securely without compromising sensitive data.

->Configuration Management: Configuration management tools, such as Ansible, Chef, or Puppet, often rely on specific user accounts for managing configurations across multiple servers. Properly configuring user accounts ensures that these tools can carry out their tasks effectively.

->Continuous Integration and Continuous Deployment (CI/CD): In CI/CD pipelines, user management is crucial for granting access to various deployment environments and tools used in the automation process.

->Disaster Recovery: User management also plays a role in disaster recovery scenarios. Properly managing user accounts helps in restoring services and data access during recovery processes.

Few Important commands

1.chmod

The chmod command is used to change the permissions (read, write, and execute) of files and directories. It allows you to control access to files and define who can read, write, or execute them. The chmod command is essential for managing the security of files and ensuring proper access control on a Linux system.

The general syntax of the chmod command is as follows:

chmod options permissions filename

Here, options can be used to specify additional settings, and permissions define the desired file permissions in numeric or symbolic notation. filename is the name of the file or directory on which the permissions need to be changed.

Numeric Notation:

  • 4: Read permission (r)

  • 2: Write permission (w)

  • 1: Execute permission (x)

To set permissions using numeric notation, you add the values of desired permissions. For example, to give read and write permissions to the owner and read-only permission to others, you use:

chmod 644 filename

Symbolic Notation:

  • u: User/Owner

  • g: Group

  • o: Others

  • a: All (equivalent to ugo)

To set permissions using symbolic notation, you use symbols to represent the permissions. For example, to give read and execute permissions to the owner and the group, you use:

chmod u+rx filename

Commonly Used chmod Options:

  • -R: Recursively change permissions for a directory and its contents.

  • -v: Verbose mode, displays a message for each file processed.

  • -c: Like -v, but only displays a message if a change is made.

  • --help: Display the help information for the chmod command.

Important chmod Examples:

  1. Give read, write, and execute permissions to the owner, read, and execute permissions to the group, and read-only permissions to others for the file myfile.txt:

     chmod 755 myfile.txt
    
  2. Recursively give read and write permissions to the owner and the group for all files and directories inside the mydir directory:

     chmod -R ug+rw mydir
    
  3. Revoke write and execute permissions from others for the file myapp.sh:

     chmod o-wx myapp.sh
    
  4. Set permissions to allow everyone to read and execute the script myscript.sh, but only the owner can modify it:

     chmod 755 myscript.sh
    

Remember that changing permissions using chmod can affect the security and functionality of files and directories, so be careful when altering permissions, especially with the chmod -R option for directories and their contents. Always ensure that you understand the implications of the permissions you set.

2.chown

The chown command is used to change the ownership of files and directories. Ownership in Linux is determined by the user and group associated with each file. The chown command allows you to transfer ownership of a file or directory to a different user and/or group.

The general syntax of the chown command is as follows:

chown [options] new_owner:group file(s)

Here, new_owner is the new user to whom the ownership is transferred, and group is the new group associated with the file. If you want to change the user only or the group only, you can leave out the :group part.

Commonly Used chown Options:

  • -R: Recursively change ownership for a directory and its contents.

  • -v: Verbose mode, displays a message for each file processed.

  • -c: Like -v, but only displays a message if a change is made.

  • --help: Display the help information for the chown command.

Examples of chown Command:

  1. Change the owner of a file named myfile.txt to a user named john:

     chown john myfile.txt
    
  2. Change the owner and group of a directory named mydir to a user named alice and a group named developers:

     chown alice:developers mydir
    
  3. Recursively change the owner and group of all files and directories inside mydir to a user named admin and a group named admins:

     chown -R admin:admins mydir
    
  4. Change the owner of a file named myapp.sh to a user named developer without affecting the group ownership:

     chown developer myapp.sh
    

The chown command should be used with caution, as changing ownership can have significant implications for file access and security. Be sure to understand the implications of changing ownership before using this command. Additionally, you typically need administrative privileges (root or sudo access) to change ownership of files and directories outside your user's ownership.

User Management commands in Linux

CommandDescription
adduserAdds a new user account to the system.
useraddAdds a new user account to the system (lower-level command).
userdelDeletes a user account from the system.
passwdSets or changes the password of a user account.
suSwitches to another user account or becomes the root user.
sudoExecutes commands with administrative privileges.
groupsDisplays the groups a user belongs to.
usermodModifies user account properties, such as username or group.
chfnAllows users to change finger information (e.g., full name).
idDisplays user and group IDs for a specified user.
newgrpChanges the current group without logging out and in.
gpasswdManages group passwords and administrators.