#Day2 AWS and DevOps Challenge : Understanding Linux Permissions And Vi editor

#Day2 AWS and DevOps Challenge : Understanding Linux Permissions And Vi editor

Table of contents

Linux is renowned for its robust security features, and at the heart of its security model are file and directory permissions. Permissions control who can access, modify, or execute files and directories on a Linux system. In this article, we'll explore some essential commands for managing permissions: chmod, chown, useradd, and groupadd.

1. chmod - Changing File Permissions

The chmod command allows you to modify file permissions. It uses a numeric representation or symbolic notation to specify permissions. Here are some common options:

  • chmod +x file: Adds execute permission to a file.

  • chmod -r folder: Recursively changes permissions for a folder and its contents.

  • chmod u+r file: Adds read permission for the file's owner.

  • chmod g-w file: Removes write permission for the file's group.

Example:

chmod 755 myfile.sh

2. chown - Changing File Ownership

The chown command is used to change the owner and group of a file or directory. Here's how it works:

  • chown user:group file: Changes the owner and group of a file.

  • chown -R user:group folder: Recursively changes ownership for a folder and its contents.

Example:

chown aniket:devopsEng myfile.txt

This command changes the owner of myfile.txt to the user john and the group to developers.

3. useradd - Adding Users

The useradd command is used to add new users to a Linux system. Here are some options:

  • useradd -m username: Creates a new user and creates a home directory for them.

  • useradd -g groupname username: Adds a user to a specific group.

  • useradd -s /bin/bash username: Sets the user's default shell.

Example:

useradd -m -g devopsEng -s /bin/bash john

This command creates a new user named john, adds them to the developers group, and sets their default shell to /bin/bash.

4. groupadd - Adding Groups

The groupadd command is used to create new groups on a Linux system. Here's how to use it:

  • groupadd groupname: Creates a new group.

Example:

groupadd devopsEng

This command creates a new group called developers.

Understanding and effectively using these Linux commands is crucial for managing permissions and access control on your system. With the right permissions, you can ensure that your files and directories are secure and accessible to the appropriate users and groups, making Linux a powerful and secure platform for various tasks.

VIM editor :

Introduction to Vim Editor

Vim is a powerful and highly configurable text editor that is renowned for its efficiency and versatility. It is often considered one of the quintessential tools for both programming and general text editing on Unix-like systems. Vim offers a steep learning curve but provides unmatched productivity once you get the hang of it.

Key Vim Shortcuts and Commands

  1. Entering and Exiting Vim:

    • Open a file: vim filename

    • Save changes: :w

    • Save and exit: :wq or :x

    • Exit without saving changes: :q!

  2. Navigation:

    • Move cursor left, right, up, down: h, l, k, j

    • Move to the beginning of the line: 0 or ^

    • Move to the end of the line: $

    • Move to the beginning of the document: gg

    • Move to the end of the document: G

  3. Editing:

    • Enter insert mode: i (before cursor), I (beginning of line), a (after cursor), A (end of line)

    • Delete character: x

    • Undo: u

    • Redo: Ctrl + r

    • Copy (a line): yy

    • Copy(n number of lines): nyy

    • Cut (delete): dd

    • Cut(delete n number of lines): ndd

    • Paste (paste after cursor): pp

    • Paste(before cursor): shift + p

  4. Searching and Replacing:

    • Search forward: /search_term

    • Search backward: ?search_term

    • Find next occurrence: n

    • Find previous occurrence: N

    • Replace: :%s/old/new/g (replace all occurrences in the document)

  5. Visual Mode:

    • Enter visual mode: v (character-based selection), V (line-based selection)

    • Copy selected text: y

    • Cut selected text: d

  6. Working with Buffers and Windows:

    • Open a new file: :e filename

    • Switch between open files: :bnext (next buffer), :bprev (previous buffer)

    • Split windows horizontally: :split

    • Split windows vertically: :vsplit

    • Switch between windows: Ctrl + w + w

Summary

Understanding Linux commands like chmod, chown, useradd, and groupadd is crucial for managing permissions and bolstering system security, ensuring that your files and directories are both safeguarded and accessible to the right users or groups, thus solidifying Linux as a reliable and secure platform for various tasks. Additionally, we explored Vim, a versatile text editor renowned for its efficiency and robust command-driven interface, offering a wealth of shortcuts and features for text editing and programming. By mastering these skills, whether you're a system administrator, developer, or Linux enthusiast, you can significantly boost your productivity and security in a Linux environment, essential for proficiently handling file management, user administration, and text editing duties.