This week, I explored๐ญ two essential aspects of working with Linux: managing permissions ๐ and getting comfortable with the Vim editor โ๏ธ. Both are crucial for anyone working in a Linux environment. Letโs break down what Iโve learned ๐.
VI & VIM Editor
VIM is a built in editor in Linux. Well we have VS Code and editor to edit or create file, why we use VIM.
- For small modifications๐ง it is faster especially when working in CLI.
- Faster to create and edit at the same timeโฐ.
- It Support Multiples formats
- While working on remote servers it is very useful.
To open file with VIM write this command in CLI
vim <file_name>
VIM have two modes๐ Command Mode and Insert Mode:
Command Mode :- This is the default mode. In this you can't edit the text. But you can navigate, search, delete, undo etc.
Insert Mode :- This mode allows you to enter text, edit text etc.
To switch to insert mode press i key.
After adding some text you need to save and exit the editor, for that simply press esc key. Then type :-
:wq!
This command writes the file to disk and quit vim editor.
To quit vim without saving the changes then type :-
:q!
In a file to remove whole line you can use command dd
this delete entire line. To delete๐๏ธ multiple line then use type d20
here 20 means number of lines, you can just count the lines from where you want to delete. For Undo type u. To jump to a specific line use command 16G
here 16 is line number. To search use /pattern
.
Note:- When I say command then it should be written in command mode only. Commands don't work in Insert Mode.
NANO Editor
Nano is more user friendly than vim. To make file or to open file use command :-
nano filename
This opens nano editor. You can see various commands at the end of the editor use these to navigate through it. I recommend to use all commands and try out every one.
Managing Permissions ๐
In a linux system there are 3 user๐ค categories:-
- Superuser Account๐ฆน๐ปโโ๏ธ:- In this root user have unrestricted permissions. For administrative tasks you need to login as root user.
- Regular User Account๐๐ปโโ๏ธ:- A user we create to login into the system. For eg. /home/pal.
- Service user๐น:- It is relevant for Linux Server Distributions.
How To Manage permissions? There are two levels first User Level and second is Group Level. In User Level we give permissions to user directly. In Group Level we group users into linux groups and then give permission to that group.
All users information is stored๐ช in /etc/passwd. This stores user account information. Everyone can read it, but only root user can change the file. After running๐๐ป this command you will get information of the user,
pal:x:1000:1000:pal,,,:/home/pal:/bin/bash
The above line represent this:- USERNAME:PASSWORD:UID:GID:GECOS:HOMEDIR:SHELL
To create new user, use command
sudo adduser<username>
It automatically chooses UID and GID values and creates a home directory for new user. After running this command enter new password and other details.
To change the password of user
sudo passwd<username>
To login to this username use su-.
To add group use this command:-
sudo groupadd<groupname>
By default, the system assigns the next available GID ๐ข.
You noticed that we can write the command adduser as useradd, so what is the difference between adduser and useradd, and similarly groupadd and addgroup? ๐ค
adduser & addgroup โก๏ธ These are more interactive ๐ฌ, more user-friendly ๐. It is easier to use and automatically chooses UID and GID values itself. Use these commands when you are executing manually ๐ฑ๏ธ.
useradd & groupadd โก๏ธ In these commands, you need to provide the information yourself ๐ ๏ธ. These commands are used when executing in an automated way ๐ค.
To change a user's group to another group, use:
sudo usermod[Options]<username>
There are various tags use linux man page to access all tags related to usermod command or you can use google to search it.
To delete group use
sudo delgroup <groupname>
Ownership And Permissions ๐ค๐
In simple words ownership means who owns the file or who have access to that file. Owner is the user, who created the file, and owning group is the primary group of that use. To change the ownership use command
sudo chown <username>:<groupname> <filename>
To understand it better lets use this command ls -l
. This shows long view of the directory.
I'll take drwxrwxr-x 2 pal pal
as a example your terminal should have this type of oputput.
d :- This is the file type. There are are different file types. "-" is for regular file, "d" is for directory, "c" is for character device file, "l" symbolic link, etc.
rwx :-First group of rwx is for owner. This indicates owner have access to this file, "r" stands for read, "w" stands for write, "x" stands for execute, "-" stands no permission.
rwx :- Second group of rwx is for group owner.
r-x :- This is for all other users, who are not the file owner or don't belong to the group owner.
Note - If "-" is used in place of rwx it means anyone is missing, don't have permission. For example r-x in this w is missing and instead of w, "-" is used this means it don't have permission for write.
To remove permission use, here - stands for removing the permission and g stands for group.
sudo chmod g-w <filename>
To add permission use, here + stands for adding the permission. For user use u instead of g.
sudo chmod g+x <filename>
Note ๐: You can use the absolute numeric method to give permission. You can search it on Google ๐. For each number, there is a permission assigned, for example, 7 is for rwx.
Resources ๐
- If you want to access the Linux terminal online, use this website: https://bellard.org/jslinux/ ๐
- Use ChatGPT ๐ to explore more. ๐ค
Wrapping Up And Getting Ready for Another Learning Adventure ๐
Last week, I took a deep dive into managing permissions in Linux ๐, mastering the Vim editor โ๏ธ, and learning about access controls ๐ก๏ธ. Each of these topics has given me a strong foundation in how Linux handles file security and text editing. I know this will be helpful when I set up my remote VM for my DevOps projects ๐ป.
In this week, Iโm excited to explore shell scripting ๐ and networking in Linux ๐! Shell scripting will open up new possibilities for automating tasks ๐ and making my workflow more efficient, while understanding Linux networking will give me the knowledge to configure and troubleshoot connections in various environments ๐ ๏ธ.
Stay tuned for more Linux and open-source adventures next week! ๐
You can check my blog on hashnode too.
Top comments (0)