Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

Linux Users, Groups and sudo for Beginners

Let's start. In the previous chapter ls -l showed us a - or a d at the start of every line. Now we read the rest of that line: the nine r w x letters, and the two names after them, the owner and the group. They answer one question: who may do what with this file? To see why that matters, we'll make real users for a small team, log in as them, use sudo the right way, change permissions with chmod, share files with a group, and end with your first shell script. Keep your server running and type every command with me.

In this class

  • Why the owner and group columns in ls -l matter
  • The team story: why one shared ec2-user is risky
  • IAM users vs Linux users
  • The default users on each Linux
  • Why a new user gets a group with the same name
  • sudo adduser, and the longer sudo su → adduser → exit route
  • Logging in with SSH as the new user (the authorized_keys steps)
  • touch vs sudo touch: who owns the file
  • whoami, who and w: three different answers
  • The / tree and where ec2-user may write
  • When to use sudo, and when not to
  • r w x for u, g and o
  • chmod u-r, u+r, u-w, u+w: a live demo with real messages
  • sudo overrides permissions; "Operation not permitted" when you're not the owner
  • Sharing with a group: groupadd, usermod -aG, chgrp, chmod g+w
  • Why your new files show rw-rw-r-- (664) and not rw-r--r-- (644)
  • The x bit and your first script, my.sh
  • An endless-loop script, and why Ctrl+C matters
  • Try-at-home tasks

1. Why the owner and group columns matter

On your laptop you are the only person. A server is shared: many people and programs work on it at the same time. Linux needs to know who owns each file and who else may touch it. Two columns in ls -l say exactly that.

In your home folder, with one file and one folder:

[ec2-user@ip-172-31-xx-xx ~]$ ls -l
total 4
-rw-rw-r--. 1 ec2-user ec2-user 6 Jan  5 10:15 my.txt
drwxr-xr-x. 2 ec2-user ec2-user 6 Jan  5 10:15 ravi

Read the start of each line:

  1. First character: - = file, d = directory (last chapter).
  2. Next nine characters: three groups of r w x. Section 12 explains them.
  3. First name (ec2-user): the owner, the user who owns the file.
  4. Second name (ec2-user): the group the file belongs to.

The other columns (links, size, date) were explained in Linux mv and rm Commands: Move, Rename and Delete Files.

Handwritten board: ls -l at the top; two lines starting with a dash and a d, each followed by three boxed sets of r w x letters; ec2-user ec2-user on each line with user written under the first column and group under the second; an arrow from my.txt to the owner; on the left r arrow read, w arrow write, x arrow execute.

Whiteboard: ls -l with the boxed type and r w x sets for a file and a folder, the owner column marked user, the group column marked group, and r = read, w = write, x = execute.

Reading ls -l: who owns the file, and whomay do what $ ls -l-rw-rw-r--. 1 ec2-user ec2-user 6 Jan 510:15 my.txtdrwxr-xr-x. 2 ec2-user ec2-user 6 Jan 510:15 ravi type: - file, d directory u: what the owner may do g: what group members may do o: what everyone else may do owner (user) group rread: open and see the content wwrite: change and save it xexecute: run it as a program -that permission is missing Always the same order: r w x, three times, for u, g and o.

Figure 1. ls -l: the type, then r w x three times for the user (owner), the group and others, then the owner name and the group name.

2. The team story: why one shared ec2-user is risky

Suppose we are building an Instagram-like app. The website, the backend for the mobile app and a MySQL database all run on one server. The backend alone can have thousands of files, and a team of five developers works on it.

The parts of the app:

  1. Frontend, what the user sees: the Android app (Java or Kotlin, packed as an APK), the iOS app (Swift or Objective-C, packed as an IPA), cross-platform apps (React Native, Flutter), and the website (React, Angular).
  2. Backend, the code on the server: PHP, Python, Java, .NET or Node.js (often with Express.js). For example, when the app asks for new reels, a file such as latest.php reads the database and sends the data back.
  3. Database: MySQL keeps the data.

The server sends only data, not the screen. Phones, tablets, TVs and car screens are all different sizes, so the app on each device draws its own screen.

Handwritten board: a box Front-end with three branches Android, ios app and webapp; a box backend with a line to server and python; Db with an arrow to MySQL.

Whiteboard: The frontend goes to the Android app, the iOS app and the web app; the backend is the server side, for example Python; the database is MySQL.

Express.js is a backend framework that runs on Node.js. PHP and Python are server-side (backend) languages too.

The problem. All five developers log in as ec2-user with the same .pem key. One day a folder of code is deleted, by mistake or on purpose. Who did it? Every file and every action says ec2-user. There is no way to tell.

Classroom line

If one of them deletes it, how will we know who did it?

The fix: one Linux user per person. Ravi logs in as ravi, Ramesh as ramesh, and every file shows who made it.

One shared login, or one Linux user perperson? Everyone logs in as ec2-user dev 1 dev 2 dev 3 dev 4 dev 5 ec2-user -rw-rw-r--. ec2-user ec2-user upload.php A file is deleted. Who did it?Every action says ec2-user. One Linux user per person raviramesh ravi ramesh -rw-rw-r--. ravi ravi ravi.txt -rw-rw-r--. ramesh ramesh ramesh.txt Every file shows who made it.

Figure 2. Left: five developers share ec2-user, so a deleted file can't be traced to anyone. Right: ravi and ramesh have their own users, and ls -l shows the owner of every file.

Each developer connects from their own network, so the IP address isn't the issue. The real problem is the shared username and shared key: Linux records ec2-user for everyone, so actions can't be tied to a person.

3. IAM users vs Linux users

Check which system is answering the permission question

Imagine Ravi can start an EC2 instance from the AWS console. That permission was for an AWS API action and came from his AWS identity. When he arrives at the Linux SSH prompt, Linux checks the account he used to log in and the groups that account belongs to. That second identity determines which server files he can read. Giving an AWS role an EC2 permission will not create a local Linux account.

Run whoami and id inside the lab instance. Record the username and groups. Now look at the AWS account and role shown in your console. If Ravi can open the console but cannot edit a file on the server, start with the Linux identity and permissions. If the launch button fails with an AWS permission error, start with the AWS role.

We already made IAM users in AWS IAM User, Root User and MFA: Launch Your First EC2 Instance. Aren't those enough?

They are two different layers:

  1. IAM users work on the AWS account: launching, stopping or terminating servers, opening the console, creating volumes. CloudTrail can show which IAM user launched a server.
  2. Linux users work inside one server: who owns a file, who may edit it, who logged in with SSH.

IAM has no idea who edited latest.php inside Linux.

Classroom line

The IAM user's job ends at launching the server.

Classroom line

It has nothing to do with the work we do inside the server.

Two different kinds of users AWS account: IAM users launch, stop or terminate servers, open the console, createvolumes Inside one EC2 server (Linux): Linux users own files and folders, log in with SSH, read, write and run files root superuser ec2-user default user ravi new user ramesh new user IAM does not see who edited a file inside Linux. Linux users do.

Figure 3. IAM users act on the AWS account. Inside one server, Linux users such as root, ec2-user, ravi and ramesh own files and log in with SSH.

Ravindra Bagale's Tip

There is one bridge between the two: AWS Systems Manager Session Manager lets IAM decide who may open a shell on a server, and can log those sessions. With plain SSH, as in this course, Linux users are what keep people apart.

4. The default users

Every Linux server starts with two users you can log in as or use:

  1. root: the superuser. It owns the system folders and may do anything.
  2. One normal user made by the cloud image, so you don't log in as root:
Server image Default user
Amazon Linux ec2-user
Ubuntu ubuntu
CentOS centos (CentOS Stream 9 images use ec2-user)
Debian admin

Classroom line

Linux has two users from the start, by default.

On CentOS cloud images the default user is centos (the newer CentOS Stream 9 images use ec2-user). admin is the default user on Debian images.

Homes. Normal users live in /home/<name>: /home/ec2-user, later /home/ravi. root's home is /root, not /home/root.

The prompt tells you who you are: $ at the end for a normal user, # for root.

5. A new user gets a group with the same name

When you share files with a teammate you give access through a group. Knowing that every user already has a private group of their own explains the ravi ravi you see in ls -l.

Every user gets a group with the same name, and that group becomes the user's main group:

User Main group
root root
ec2-user ec2-user
ravi ravi

That's why ls -l showed ec2-user ec2-user: owner ec2-user, group ec2-user.

See it yourself:

id ec2-user
uid=1000(ec2-user) gid=1000(ec2-user) groups=1000(ec2-user),4(adm),10(wheel),190(systemd-journal)

gid=1000(ec2-user) is the main group. wheel is the group that may use sudo.

6. Creating a user: sudo adduser

Only root may create users. You are ec2-user, so you need root's help for that one command.

The long way (three commands):

[ec2-user@ip-172-31-xx-xx ~]$ sudo su
[root@ip-172-31-xx-xx ec2-user]# adduser ravi
[root@ip-172-31-xx-xx ec2-user]# exit
exit
[ec2-user@ip-172-31-xx-xx ~]$
  1. sudo su: sudo = "superuser do", su = "switch user". Together: become root. The prompt changes to root and ends with #.
  2. adduser ravi: root creates the user.
  3. exit: back to ec2-user, $ again.

The short way (one command):

sudo adduser ravi

Classroom line

We can turn these three commands into one, like this.

What it creates: a user ravi, a group ravi, and a home folder /home/ravi.

Classroom line

A group named ravi will be created too, and a folder named ravi as well.

Check it:

sudo adduser ramesh
id ravi
uid=1001(ravi) gid=1001(ravi) groups=1001(ravi)
ls /home
ec2-user  ramesh  ravi
What sudo adduser ravi creates [ec2-user@ip-172-31-xx-xx ~]$ sudo adduser ravi [ec2-user@ip-172-31-xx-xx ~]$ 1. a user ravi uid=1001(ravi) 2. a group with the same name ravi gid=1001(ravi) 3. a home folder /home/ravi drwx------. ravi ravi Check: id ravi and ls /home. No output from adduser means it worked. On Amazon Linux, adduser is the same program as useradd: it asks noquestions and sets no password.

Figure 4. Animation: sudo adduser ravi creates the user ravi, a group ravi with the same name, and the home folder /home/ravi, which only ravi can open.

The commands are adduser and useradd. On Amazon Linux 2023, adduser is just another name for useradd: it asks nothing and sets no password (set one with sudo passwd ravi only if you need it). On Ubuntu, adduser is a friendlier script that asks for a password and details.

7. Logging in with SSH as the new user

Ravi should log in as ravi, not as ec2-user. But a brand-new user has no key, and password login is switched off on EC2. So this fails at first:

ssh -i key.pem ravi@SERVER_PUBLIC_IP
ravi@SERVER_PUBLIC_IP: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Put a public key into /home/ravi/.ssh/authorized_keys. For practice, copy ec2-user's key (it matches your .pem). Run these as ec2-user:

sudo mkdir /home/ravi/.ssh
sudo cp ~/.ssh/authorized_keys /home/ravi/.ssh/
sudo chown -R ravi:ravi /home/ravi/.ssh
sudo chmod 700 /home/ravi/.ssh
sudo chmod 600 /home/ravi/.ssh/authorized_keys

What each line does:

  1. Make the .ssh folder in Ravi's home.
  2. Copy the list of allowed public keys into it.
  3. Make ravi the owner (until now root owned them, because root made them).
  4. Only ravi may open the folder (700).
  5. Only ravi may read and write the key list (600).

Now the same command works, and the prompt shows the new user:

ssh -i key.pem ravi@SERVER_PUBLIC_IP
[ravi@ip-172-31-xx-xx ~]$ touch ravi.txt
[ravi@ip-172-31-xx-xx ~]$ ls -l
total 0
-rw-rw-r--. 1 ravi ravi 0 Jan  5 10:15 ravi.txt

The file says ravi ravi. Ramesh's files will say ramesh ramesh.

ssh -i key.pem ravi@... works only after a public key is in /home/ravi/.ssh/authorized_keys. SSH also refuses keys in folders that are too open, which is why the chown and chmod 700/600 lines matter. In a real team, each person sends their own public key and you put that one in, so nobody shares a .pem.

8. touch vs sudo touch: who owns the file

Ownership decides who may later edit or chmod a file. A file made with sudo by mistake belongs to root, and then you can't change it without sudo again.

The user who runs a command owns what it creates.

[ec2-user@ip-172-31-xx-xx ~]$ touch a.txt
[ec2-user@ip-172-31-xx-xx ~]$ sudo touch b.txt
[ec2-user@ip-172-31-xx-xx ~]$ ls -l
total 0
-rw-rw-r--. 1 ec2-user ec2-user 0 Jan  5 10:15 a.txt
-rw-r--r--. 1 root     root     0 Jan  5 10:15 b.txt
  1. touch a.txt: ec2-user made it, so ec2-user ec2-user.
  2. sudo touch b.txt: root made it, so root root.

Classroom line

Put sudo in front of any command; it simply means the root user is doing that work.

(Section 17 explains why the two files got different permissions, rw-rw-r-- and rw-r--r--.)

9. whoami, who and w

On a shared server you often need to know who you are right now (after su it can change) and who else is logged in before you restart something.

Three short commands, three different answers:

  1. whoami: your current user name.
  2. who: everyone who is logged in right now, with their terminal and login time.
  3. w: everyone logged in, plus how long the server has been up, the load, and what each person is running.

Try them. Your own output will show your times and IP addresses:

whoami
ec2-user

sudo whoami
root

Then with Ravi logged in too (the IP addresses here are examples):

who
ec2-user pts/0        2026-01-05 10:15 (203.0.113.25)
ravi     pts/1        2026-01-05 10:18 (203.0.113.40)

w
 10:20:01 up  2:05,  2 users,  load average: 0.00, 0.01, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ec2-user pts/0    203.0.113.25     10:15    0.00s  0.03s  0.00s w
ravi     pts/1    203.0.113.40     10:18    1:02   0.01s  0.01s -bash

The three commands differ: whoami prints only your name, who lists every logged-in user, and w adds uptime, load and what each user is running.

10. The / tree and ec2-user's boundary

Everything hangs under /: bin, sbin, home, root, dev, opt, usr, var and more. root owns all of them. A normal user may write only inside its own home.

Try it without sudo:

touch /a.txt
touch: cannot touch '/a.txt': Permission denied
touch /home/a.txt
touch: cannot touch '/home/a.txt': Permission denied
mkdir /test
mkdir: cannot create directory ‘/test’: Permission denied
ls /home/ravi
ls: cannot open directory '/home/ravi': Permission denied

The last one: on Amazon Linux a new home is drwx------, so even looking inside another user's home is blocked.

Classroom line

Go to / or /home and try to make a file without sudo; it won't work, you'll get Permission denied.

With sudo, root does it:

sudo touch /home/a.txt
sudo mkdir /test
sudo touch /home/ravi/notes.txt

Write the full path, /home/ravi/notes.txt, when the file belongs in someone else's home.

Classroom line

As the root user, we can work in every folder.

Where ec2-user may write without sudo / ├─ bin sbin usr dev ├─ opt var root └─ home ├─ ravi └─ ramesh red: Permission denied without sudo /home/ec2-user └─ projects green: ec2-user can create, edit and delete here $ touch /a.txt touch: cannot touch '/a.txt': Permission denied $ ls /home/ravi ls: cannot open directory '/home/ravi': Permission denied $ sudo mkdir /test # root does it: works

Figure 5. The tree from /. ec2-user can write only inside /home/ec2-user (green). Everywhere else (red) gives Permission denied unless the command starts with sudo.

11. When to use sudo, and when not to

sudo skips every safety check. Using it for everyday work in your home creates root-owned files you then can't edit, and one typo can damage the system.

Use sudo only for work outside your home or on the system: installing packages, creating users, editing files in /etc, writing in another user's home.

Don't use sudo in your own home. You don't need it there, and it makes root-owned files that you then can't edit normally:

sudo touch notes.txt
echo hello > notes.txt
-bash: notes.txt: Permission denied

nano notes.txt opens it but says [ File 'notes.txt' is unwritable ]. You can still delete it, because the folder is yours, but rm asks first:

rm notes.txt
rm: remove write-protected regular empty file 'notes.txt'?

If you made one by mistake, give it back to yourself:

sudo chown ec2-user:ec2-user notes.txt

For a file inside ec2-user's own home, no sudo is needed: touch a.txt is enough. With sudo the file becomes root root, and you can't edit it without sudo again.

Ravindra Bagale's Tip

Before typing sudo, ask: "Am I outside my home, or changing the system?" If the answer is no, drop the sudo. And never stay in a root shell (sudo su) longer than you need; type exit as soon as the root job is done.

12. r w x for u, g and o

Read a file’s three permission groups as three tests

Suppose ls -l report.txt shows -rw-r-----, owner Ravi, group reels. Ignore the leading - for a moment. Ravi’s three bits are rw-. Group members have r--. Everyone else has ---. With ordinary Linux mode bits and no extra ACL entries, Ravi can read and edit, Ramesh can read if his current session belongs to reels, and a different user cannot do either.

For a group test, first check id inside Ramesh’s actual session and ls -l report.txt on the same file. A membership listed by an administrator may not show up in an older login. The permission bits apply to the credentials of the running process. This is why you must check the user or service that actually tried to open the file.

Every permission problem on a server, from a website that won't load to a key that SSH refuses, comes down to these nine letters. Read them first, then fix.

The nine characters are three sets of three, always in the order r w x:

  1. u = user, the owner (the first name in ls -l).
  2. g = group (the second name).
  3. o = others, every other user on the server.

In each set: r = read, w = write, x = execute, - = that permission is missing.

Examples:

  1. rw- = read and write, no execute.
  2. r-- = read only.
  3. r-x = read and execute, no write.

So -rw-r--r-- means: owner reads and writes; group reads; others read.

Handwritten board: rw- r-- r-- with user, group and other users written under the three sets; ec2-user ec2-user my.txt with an arc between the two names and ravi written under the group; in the top right corner root, ec2-user, ravi and ramesh.

Whiteboard: rw- for the user, r-- for the group and r-- for other users of my.txt, owned by ec2-user with group ec2-user; a group can also hold another user such as ravi. Top right: the users root, ec2-user, ravi and ramesh.

13. chmod: taking away the owner's own r and w

chmod (change mode) changes those nine letters. The quickest way to understand them is to take a permission away from yourself and watch what breaks.

How the commands read: chmod u-w my.txt = for the user (owner), take away (-) write. + gives it back.

Start (on Amazon Linux your new files are rw-rw-r--):

echo hello > my.txt
ls -l my.txt
-rw-rw-r--. 1 ec2-user ec2-user 6 Jan  5 10:15 my.txt

Take away read:

chmod u-r my.txt
ls -l my.txt
--w-rw-r--. 1 ec2-user ec2-user 6 Jan  5 10:15 my.txt
cat my.txt
cat: my.txt: Permission denied

nano my.txt opens an empty screen with [ Error reading my.txt: Permission denied ]. Give it back with chmod u+r my.txt.

Take away write:

chmod u-w my.txt
ls -l my.txt
-r--rw-r--. 1 ec2-user ec2-user 6 Jan  5 10:15 my.txt

nano my.txt shows the text with [ File 'my.txt' is unwritable ]. Change something and press Ctrl+O to save: [ Error writing my.txt: Permission denied ]. Press Ctrl+X to leave, then N to drop the change. Give write back with chmod u+w my.txt, and saving works again.

Taking away the owner's own r and w $ ls -l my.txt -rw-rw-r--. 1 ec2-user ec2-user 6 Jan 5 10:15 my.txt $ cat my.txt hello Start: the owner has r and w. $ chmod u-r my.txt $ ls -l my.txt --w-rw-r--. 1 ec2-user ec2-user 6 Jan 5 10:15 my.txt $ cat my.txt cat: my.txt: Permission denied nano: [ Error reading my.txt: Permission denied ] u-r: the owner cannot read it any more. chmod u+r gives it back. $ chmod u+r my.txt $ chmod u-w my.txt $ ls -l my.txt -r--rw-r--. 1 ec2-user ec2-user 6 Jan 5 10:15 my.txt nano: [ File 'my.txt' is unwritable ] save: [ Error writing my.txt: Permission denied ] u-w: the owner can read but not save, even though the group has rw. $ chmod u+w my.txt -rw-rw-r--. 1 ec2-user ec2-user 6 Jan 5 10:15 my.txt nano: [ Wrote 1 line ] u+w: saving works again. The owner can always chmod its own file. u = owner, g = group, o = others; - takes a permission away, + gives it.

Figure 6. Animation: chmod u-r makes cat say Permission denied; chmod u+r and chmod u-w make nano say the file is unwritable and saving fail; chmod u+w makes saving work again.

Handwritten board: rw- r-- r-- with u, g and o under the three sets and ec2-user ec2-user my.txt next to them; below, chmod u-w my.txt, then r-- r-- r--, then chmod u+w my.txt; on the right side of a line, chmod u-r my.txt and chmod u+r my.txt.

Whiteboard: rw- r-- r-- marked u, g and o for my.txt owned by ec2-user; chmod u-w my.txt turns it into r--r--r--, chmod u+w my.txt gives write back; on the right chmod u-r my.txt and chmod u+r my.txt.

Why didn't the group's rw- help? ec2-user is in the group ec2-user, and that group still has rw-. But Linux checks only one set: if you are the owner, it uses the u bits and stops. The g bits are for group members who are not the owner.

Which three bits does Linux check? Are you root? yes: allowed (root skips the r w xchecks) no Are you the owner? yes: only the u bits count. Stophere. no Are you in the file’sgroup? yes: only the g bits count. Stophere. no Anyone else the o bits count -r--rw-r--. ec2-user ec2-user my.txt ec2-user is the owner, so the u bits r-- apply: no saving, eventhough the group ec2-user has rw-.

Figure 7. Linux checks in order: root is allowed; the owner gets only the u bits; a group member gets the g bits; everyone else gets the o bits. So an owner with r-- can't save even when the group has rw-.

Nano closes with Ctrl+X (it asks whether to save a changed file: Y or N). Ctrl+C in nano only shows the cursor position.

Ravindra Bagale's Tip

The owner can always chmod its own file back, even after taking every permission away. So this demo is safe. Just don't try it on system files.

14. sudo overrides permissions

This is why sudo is powerful and dangerous: root can write to a file even when the file itself says nobody may write.

root skips the r w x checks. With u-w still set:

ls -l my.txt
-r--rw-r--. 1 ec2-user ec2-user 6 Jan  5 10:15 my.txt
sudo nano my.txt

Change a line, press Ctrl+O and Enter: nano says [ Wrote 1 line ]. With u-r, sudo cat my.txt still prints the text.

Classroom line

Root is above everyone; these limits don't apply to it.

That is exactly why sudo is powerful, and why it needs care.

15. "Operation not permitted": you're not the owner

If anyone could chmod any file, permissions would protect nothing. Only the owner (or root) may change them, and this error is how Linux tells you.

Only the owner, or root, may chmod a file.

sudo touch u.txt
ls -l u.txt
-rw-r--r--. 1 root root 0 Jan  5 10:15 u.txt
chmod u-w u.txt
chmod: changing permissions of 'u.txt': Operation not permitted

u.txt belongs to root, so ec2-user can't change its permissions. sudo chmod u-w u.txt would work.

Two different errors:

  1. Permission denied: the r w x bits don't allow what you tried (read, write, open).
  2. Operation not permitted: you tried something only the owner or root may do, such as chmod.

16. Groups for sharing

Ravi and Ramesh both work on the "reel upload" module. Ramesh must edit Ravi's files. Giving write to others (o+w) would let every user on the server edit them. A group gives write to the team only.

Make a team group, add both users, and use a shared folder outside the homes (homes are drwx------, so Ramesh can't even enter /home/ravi):

sudo groupadd reels
sudo usermod -aG reels ravi
sudo usermod -aG reels ramesh
sudo mkdir /srv/reels
sudo chgrp reels /srv/reels
sudo chmod g+w /srv/reels
  1. groupadd reels: a new group.
  2. usermod -aG reels ravi: add Ravi to the Group reels. Without -a, -G would replace his other extra groups.
  3. chgrp reels /srv/reels: the folder's group becomes reels.
  4. chmod g+w /srv/reels: group members may create files in it.

Check:

id ramesh
uid=1002(ramesh) gid=1002(ramesh) groups=1002(ramesh),1003(reels)
ls -ld /srv/reels
drwxrwxr-x. 2 root reels 6 Jan  5 10:15 /srv/reels

New groups apply at the next login, so Ravi and Ramesh log out and in again. Then Ravi makes a file. Its group is still ravi, so Ramesh can't write to it yet:

[ravi@ip-172-31-xx-xx ~]$ echo "<?php // upload" > /srv/reels/upload.php
[ravi@ip-172-31-xx-xx ~]$ ls -l /srv/reels/upload.php
-rw-rw-r--. 1 ravi ravi 16 Jan  5 10:15 /srv/reels/upload.php

[ramesh@ip-172-31-xx-xx ~]$ echo "// ramesh" >> /srv/reels/upload.php
-bash: /srv/reels/upload.php: Permission denied

Ravi (the owner, and a member of reels) gives the file to the team group:

[ravi@ip-172-31-xx-xx ~]$ chgrp reels /srv/reels/upload.php
[ravi@ip-172-31-xx-xx ~]$ chmod g+w /srv/reels/upload.php
[ravi@ip-172-31-xx-xx ~]$ ls -l /srv/reels/upload.php
-rw-rw-r--. 1 ravi reels 16 Jan  5 10:15 /srv/reels/upload.php

[ramesh@ip-172-31-xx-xx ~]$ echo "// ramesh" >> /srv/reels/upload.php
[ramesh@ip-172-31-xx-xx ~]$ cat /srv/reels/upload.php
<?php // upload
// ramesh

If Ravi and Ramesh keep making new files here, set the directory’s set-group-ID bit once with sudo chmod g+s /srv/reels. New files created inside then get the group reels, even when Ravi’s primary group is ravi. Create a second file and check its group with ls -l. Group ownership and permission are separate. If Ravi’s umask leaves out group write, the file still needs chmod g+w before Ramesh can edit it.

Ramesh can write now, but he still can't chmod it, because Ravi is the owner:

[ramesh@ip-172-31-xx-xx ~]$ chmod o+w /srv/reels/upload.php
chmod: changing permissions of '/srv/reels/upload.php': Operation not permitted
Sharing work with a group, not witheveryone raviramesh group: reels /srv/reels upload.php -rw-rw-r--. ravi reels upload.php u=rw- g=rw- o=r-- ravi (owner): read and writeramesh (group reels): read and writeeveryone else: read only $ sudo groupadd reels$ sudo usermod -aG reels ravi$ sudo usermod -aG reels ramesh$ sudo chgrp reels/srv/reels/upload.php$ sudo chmod g+w/srv/reels/upload.php o+w would let every user on the server write. Agroup gives write only to the team.

Figure 8. ravi and ramesh are both in the group reels. upload.php is owned by ravi with group reels and rw-rw-r--, so both can edit it and everyone else can only read it.

There is also a quick version: sudo usermod -aG ravi ramesh adds Ramesh to Ravi's own group. It works for files Ramesh can reach, but not inside /home/ravi, which only Ravi may open. A project group and a shared folder is the cleaner way.

17. Why your files show 664 and not 644

Calculate the starting permissions for one new file

A umask lists the permission bits to take away when a program creates a file or directory. It affects future creation. It does not rewrite files already on disk. In a subshell, run (umask 027; touch private-lab-note; mkdir private-lab-dir; ls -ld private-lab-note private-lab-dir) from a fresh practice directory. The parentheses keep the changed mask inside this small exercise.

On a normal lab filesystem with no inherited access rules, touch requests 666 and the mask leaves 640. A new directory can start at 777, and this mask leaves 750. Look for read and write for the file owner and group read only. The directory needs the extra search bit so you and the permitted group can enter it.

You will compare your screen with pictures and docs that show 644. Knowing where 664 comes from (the default umask on Amazon Linux) stops you from thinking something is broken.

The whiteboard pictures show new files as rw-r--r--. On Amazon Linux, the files you make as ec2-user show rw-rw-r--. Both are right; it depends on the umask, a setting that takes permissions away from every new file:

umask
0002
  1. A new file starts from rw-rw-rw- (666).
  2. ec2-user's umask 0002 removes only w for others → rw-rw-r-- (664).
  3. root's umask is 0022, which also removes w for the group → rw-r--r-- (644). That's why sudo touch made rw-r--r-- in section 8.

Amazon Linux uses 0002 for users like ec2-user because every user has a private group of their own, so group write is safe. Many other systems use 0022 for everyone, which gives the 644 in the whiteboard pictures.

As numbers: r = 4, w = 2, x = 1, added up for each set. rw- = 6, r-- = 4, rwx = 7. So 664 = rw-rw-r--, and the 700/600 from section 7 mean "only the owner".

18. The x bit and your first shell script

Suppose you type the same five commands every day. Put them in a file once, and run the file. That file is a script, and to run it Linux needs the x (execute) bit.

Handwritten board: a box holding six lines: echo enter folder name, read name with name underlined, mkdir $name, cd $name, touch $name.txt, echo $name greater-than $name.txt; on the right the word King.

Whiteboard: The first script. echo "enter folder name", read name, mkdir $name, cd $name, touch $name.txt, echo $name > $name.txt. King is a sample name typed at the prompt. The page adds #!/bin/bash and quotes around "$name".

Write it: nano my.sh, type these lines, save with Ctrl+O, Enter, and leave with Ctrl+X:

#!/bin/bash
echo "Enter a folder name:"
read name
mkdir "$name"
cd "$name"
touch "$name.txt"
echo "$name" > "$name.txt"

Line by line:

  1. #!/bin/bash (the shebang): run this file with bash.
  2. echo: prints the text back to you.
  3. read name: waits for you to type something, and stores it in the variable name.
  4. "$name": the value you typed. The quotes keep a name with spaces in one piece.
  5. mkdir, cd, touch: make a folder, go into it, make a file with the same name.
  6. echo "$name" > "$name.txt": write the name into that file.

Classroom line

What does echo do? Whatever we tell it, it says back to us.

Run it, first without x:

ls -l my.sh
-rw-rw-r--. 1 ec2-user ec2-user 120 Jan  5 10:15 my.sh
./my.sh
-bash: ./my.sh: Permission denied

Classroom line

Until we give it x permission, it won't execute.

Give the owner x, and run it:

chmod u+x my.sh
ls -l my.sh
-rwxrw-r--. 1 ec2-user ec2-user 120 Jan  5 10:15 my.sh
./my.sh
Enter a folder name:
reels
ls reels
reels.txt
cat reels/reels.txt
reels
  1. -rwxrw-r--: the owner now has x. In a coloured terminal the name turns green.
  2. ./my.sh: ./ means "the file in this folder". Without it, bash looks only in the usual command folders and says command not found.
  3. You typed reels; the script made the folder reels, the file reels/reels.txt, and wrote reels into it.
A script needs the x bit to run $ ls -l my.sh -rw-rw-r--. 1 ec2-user ec2-user 120 Jan 5 10:15 my.sh $ ./my.sh -bash: ./my.sh: Permission denied 1. No x: the shell refuses to run it. $ chmod u+x my.sh $ ls -l my.sh -rwxrw-r--. 1 ec2-user ec2-user 120 Jan 5 10:15 my.sh 2. chmod u+x gives the owner the x bit. $ ./my.sh Enter a folder name: reels $ ls reels reels.txt $ cat reels/reels.txt reels 3. ./my.sh runs every line: a folder, a file inside it, and the text. ./ means: the file in this folder. Without it, the shell looks only in the usualcommand folders.

Figure 9. Animation: ./my.sh fails with Permission denied without the x bit; chmod u+x my.sh adds it; ./my.sh then asks for a name and creates the folder and the file.

Two things to notice:

  1. After the script ends, you are still in the same folder. The cd happened inside the script's own shell, not in yours.
  2. Run it again with the same name and mkdir says mkdir: cannot create directory ‘reels’: File exists. Try another name, such as my notes: thanks to the quotes you get one folder, my notes. Without the quotes, mkdir $name would make two folders, my and notes.

Start every bash script with #!/bin/bash, and quote variables: mkdir "$name", cd "$name", touch "$name.txt". Also, read is a shell built-in command (type read says read is a shell builtin).

19. An endless loop, and Ctrl+C

Sooner or later a script or command hangs. Ctrl+C is how you stop it without closing the terminal or rebooting the server.

A script can repeat forever. Make loop.sh:

#!/bin/bash
while true; do
  echo "Hello"
  sleep 1
done
  1. while true; do ... done: repeat the lines between do and done as long as true is true, which is forever.
  2. sleep 1: wait one second each time.

Run it:

chmod u+x loop.sh
./loop.sh
Hello
Hello
Hello
^C

It prints Hello every second until you press Ctrl+C, which stops the program running in the foreground of your terminal.

Classroom line

Whenever you get stuck anywhere, cancel it: Ctrl+C.

The loop is written while true; do (or while :; do). An endless loop is not harmful in itself; it shows how a runaway script can keep running and using CPU until you stop it. That's why Ctrl+C is worth remembering.

20. Hands-on lab: users, ownership and permissions on one server

Permissions only make sense when you watch them block you. This lab creates real users, makes files as different users, takes rights away and gives them back, then cleans everything up.

  1. Read your own file
    • Command: cd && echo hello > my.txt && ls -l my.txt
    • You should see: -rw-rw-r--. 1 ec2-user ec2-user 6 ... my.txt
    • Check: Owner and group are both ec2-user.
    • Why: The user who creates a file owns it. rw-rw-r-- is 664, the Amazon Linux default for your files.
  2. Make a file as root
    • Command: sudo touch root.txt && ls -l root.txt
    • You should see: -rw-r--r--. 1 root root 0 ... root.txt
    • Check: echo hi >> root.txt → -bash: root.txt: Permission denied
    • Why: sudo runs the command as root, so root owns the result, even inside your home. That is why you avoid sudo for everyday files.
  3. Create a user
    • Command: sudo adduser ravi
    • You should see: Nothing.
    • Check: id ravi → uid=1001(ravi) gid=1001(ravi) groups=1001(ravi)
    • Why: Only root may add users. Linux also makes a group ravi and a home /home/ravi, so Ravi's files stay apart from everyone else's.
  4. Check who you are
    • Command: whoami
    • You should see: ec2-user
    • Check: who lists your own login line (ec2-user pts/0 ...).
    • Why: Creating ravi didn't change who you are. whoami is your current user; who is everyone logged in.
  5. Take away your own write
    • Command: chmod u-w my.txt && echo more >> my.txt
    • You should see: -bash: my.txt: Permission denied
    • Check: ls -l my.txt starts with -r--rw-r--.
    • Why: u-w removes write for the owner. Even though you own the file, Linux checks the u bits and refuses.
  6. Watch sudo ignore it
    • Command: echo more | sudo tee -a my.txt
    • You should see: more
    • Check: cat my.txt → hello then more.
    • Why: root skips the r w x checks. tee -a appends as root; a plain sudo echo ... >> my.txt would fail, because the >> is done by your own shell, not by root.
  7. Give write back
    • Command: chmod u+w my.txt
    • You should see: Nothing.
    • Check: ls -l my.txt starts with -rw-rw-r-- again.
    • Why: Only the owner or root may chmod. You own my.txt, so no sudo is needed.
  8. Try to chmod root's file
    • Command: chmod u-w root.txt
    • You should see: chmod: changing permissions of 'root.txt': Operation not permitted
    • Check: ls -l root.txt is unchanged.
    • Why: You are not the owner. "Operation not permitted" means "not yours", which is different from "Permission denied" (the bits say no).
  9. Share through a group
    • Command: sudo adduser ramesh && sudo usermod -aG ravi ramesh
    • You should see: Nothing.
    • Check: id ramesh ends with groups=1002(ramesh),1001(ravi).
    • Why: Now anything Ravi gives g+w to, Ramesh can edit, without opening it to every user with o+w. -a appends; without it, -G would replace Ramesh's other groups.
  10. Write a script and run it
    • Command: echo 'echo Hello from my script' > hello.sh && ./hello.sh
    • You should see: -bash: ./hello.sh: Permission denied
    • Check: chmod u+x hello.sh && ./hello.sh → Hello from my script
    • Why: A new file has no x, so Linux won't run it as a program. u+x lets you, the owner, run it; nobody else gets anything new.
  11. Clean up
    • Command: sudo userdel -r ramesh && sudo userdel -r ravi && sudo rm -f root.txt && rm -f my.txt hello.sh
    • You should see: Nothing.
    • Check: id ravi → id: 'ravi': no such user
    • Why: -r also removes the home folder, so no orphan files stay behind. Ramesh goes first because he is a member of Ravi's group.
  12. sudo touch and sudo mkdir show root as owner
    • Command: cd ~ && sudo touch a.txt && sudo mkdir test && ls -l a.txt && ls -ld test
    • You should see: owner and group both root on a.txt and on test (for example -rw-r--r--. 1 root root and drwxr-xr-x. 2 root root).
    • Check: Without sudo, touch/mkdir would show ec2-user ec2-user.
    • Why: Class proved ownership comes from who runs the command — sudo means root created them.
  13. Give the group write with chmod g+w
    • Command: touch share.txt && ls -l share.txt && chmod g+w share.txt && ls -l share.txt
    • You should see: group column gains w (for example from rw-r--r-- toward rw-rw-r--, exact start depends on umask).
    • Check: Only the middle trio (group) changed; owner and others stayed unless you asked otherwise.
    • Why: Teams share a project folder by group write instead of sharing one login.
  14. Another user: Permission denied on your private folder
    • Do: As ec2-user: mkdir -p tatya && echo hello > tatya/tatya.txt && chmod 700 tatya. Then SSH or su as your practice user and run ls -l tatya and cat tatya/tatya.txt.
    • You should see: Permission denied for both (or for ls/cat depending on bits).
    • Check: 700 = only owner may enter and read — other Linux users are blocked even on the same server.
    • Why: IAM users ≠ Linux users; isolation is why you create separate accounts for teammates.
  15. nano script with a read prompt, then run it
    • Command: nano my.sh — type:
      #!/bin/bash
      read -p "Your name: " n
      echo "Hello, $n"
      Save: Ctrl+X, Y, Enter. Then: chmod u+x my.sh && ./my.sh and type a name.
    • You should see: prompt Your name:, then Hello, plus what you typed. Without chmod u+x, ./my.sh may say Permission denied.
    • Check: x on a file means “run as a program”; scripts need it for ./name.
    • Why: Class tied the execute bit to real scripts, not only folders.

21. Try at home

Try at home

Task 1: users

  1. Create the users ravi and ramesh with sudo adduser. Check with id ravi and ls /home.
  2. Set up /home/ravi/.ssh/authorized_keys (section 7) and log in as ravi from a second terminal.
  3. As ravi, run whoami, then touch ravi.txt and ls -l. In the ec2-user terminal, run who and w.

Task 2: sudo

  1. As ec2-user, try touch /a.txt. Read the error. Then do it with sudo and check the owner with ls -l /a.txt.
  2. In your home, run touch x.txt and sudo touch y.txt. Compare the owner and the permissions.
  3. Give y.txt back to yourself with sudo chown ec2-user:ec2-user y.txt.

Task 3: chmod

  1. echo hello > my.txt, then chmod u-r my.txt and cat my.txt. Then chmod u+r my.txt.
  2. chmod u-w my.txt, open it in nano, try to save, leave with Ctrl+X. Then chmod u+w my.txt.
  3. sudo touch u.txt and try chmod u-w u.txt. Which error do you get, and why?

Task 4: groups and scripts

  1. Repeat section 16 with a group web and a folder /srv/web.
  2. Write my.sh (section 18), run it before and after chmod u+x, and test it with a name that has a space.
  3. Write loop.sh, run it, and stop it with Ctrl+C.

When you finish, delete the practice users with sudo userdel -r ravi and sudo userdel -r ramesh, then stop the instance (or terminate it if you won't use it again).

Common errors and fixes

Error / symptomFix
Permission denied on ./script.shchmod u+x script.sh (and ensure shebang line exists).
Cannot edit a file you “own” after sudo nano created itFile is root-owned — sudo chown ec2-user:ec2-user file or edit with sudo.
chmod on root’s file as normal userOnly root (or the owner) may change mode — use sudo if appropriate.
Teammate cannot write the project folderSame group + chmod g+w (and folder x so they can cd).
Confused IAM user with Linux userIAM signs into AWS Console/API. Linux users exist inside the OS on the instance.

FAQ

Q. Why a group with the same name as the user?

Default private group: your files start belonging to you alone until you share via a project group.

Q. Does sudo make me root forever?

No. One command (or a short cached window). Then you are yourself again.

Q. r vs x on a folder?

r = list names with ls. x = enter with cd / traverse. Need both for normal browsing.

Q. umask?

Bits removed from the default when you create a file. Explains why new files are often 664 not 666 for ec2-user.

Recap

In short

  1. ls -l: type, then r w x for user (owner), group and others, then the owner name and the group name.
  2. One shared ec2-user hides who did what. Give each person their own Linux user.
  3. IAM users act on the AWS account; Linux users act inside the server.
  4. Default users: root plus ec2-user (Amazon Linux), ubuntu, centos (CentOS) or admin (Debian). root's home is /root. $ = normal user, # = root.
  5. sudo adduser ravi creates the user, a group ravi and /home/ravi. Long way: sudo su, adduser ravi, exit.
  6. SSH as ravi needs a key in /home/ravi/.ssh/authorized_keys, owned by ravi, with 700/600.
  7. touch → owner ec2-user; sudo touch → owner root.
  8. whoami = you; who = everyone logged in; w = everyone plus uptime, load and what they run.
  9. Without sudo, ec2-user writes only inside /home/ec2-user. Use sudo only outside your home.
  10. chmod u-r, u+r, u-w, u+w change the owner's bits. The owner gets only the u bits, even if the group has more.
  11. root skips the checks. Only the owner or root may chmod: otherwise "Operation not permitted".
  12. Share with a group: groupadd, usermod -aG, chgrp, chmod g+w, then log in again.
  13. Your files are 664 because of umask 0002; root's are 644 (umask 0022).
  14. A script needs #!/bin/bash, quoted "$name", chmod u+x, and ./my.sh to run.
  15. An endless loop is not a virus. Ctrl+C stops it. Nano exits with Ctrl+X.

Samjla ka? Ghari don users banva, tyancha group banva, ani pahila script swatah chalvun bagha.


Ravindra Bagale, trainer: linkedin.com/in/ravindra-bagale. The user, group, folder and file names (ravi, ramesh, reels, my.txt, my.sh and the rest) are examples for learning. Commands and messages were checked on the box with GNU coreutils, bash, nano and shadow-utils, and against the settings of an Amazon Linux 2023 server (adduser → useradd, home folders 700, umask 0002, nano 8.3); the hostname in the prompt, the IP addresses in who/w and the dates in ls -l are illustrative.

Worked example: who can edit one shared report?

Your report belongs to ravi:reports and shows -rw-r-----. Ravi edits it. A colleague in the reports group can read it but cannot save a change. Before reaching for sudo, confirm both facts.

  1. Run ls -l report.txt as an authorised user to see owner, group and mode. Run id in the colleague's own session to see the groups that session actually has.
  2. Decide the intended boundary. If the report should be editable by every member of reports, the owner can use chmod g+w report.txt. Check the new mode and test as the colleague. Do not add write access for other users.
  3. If the colleague still gets Permission denied, inspect the parent directory. They need permission to traverse that directory. Some editors also need directory write access to save by replacing a temporary file.
Interview question: why did it work with sudo?

The privileged process had broader access. That proves little about the permissions a normal user or service has. Confirm the target identity and fix the smallest missing permission instead.

Reference 1 · Reference 2

Practise this chapter

Interview questions and answers

How do you prove why one teammate can edit a shared file while another can only read it?

Check ls -l to see the file’s owner, group and mode. Run id in the failing user’s actual session, confirm the configured membership took effect, and check parent-directory access. The group must match and have write for editing.

Does a set-group-ID shared directory guarantee every new file is editable by the group?

It helps the group ownership stay consistent. The mode and any default ACL still determine access. Create a throwaway file as one teammate and compare the group and its permission bits before asking the second teammate to edit it.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. Ramesh belongs to the reels group. The owner Ravi created a new file in a shared reels directory, but the file’s group is ravi. Which setting helps new files inherit the directory’s reels group?

Answer and explanation

C. Set the directory’s set-group-ID bit

On a Linux lab filesystem, set-group-ID on a directory makes new entries inherit the directory’s group. Group write is still a separate permission.

2. A normal process requests mode 666 for a new file. With umask 027 and no inherited ACL, what mode should you expect?

Answer and explanation

A. 640

The mask removes group write and all other permissions from 666. The owner remains read/write, the group can read, and others get no access.

3. The same person is allowed to create EC2 but gets Permission denied opening a file in their SSH session. Where should they look first?

Answer and explanation

B. The Linux user, group and mode of that file and its parent directories

The AWS permission let the person call the EC2 service. Access to a Linux file is decided for the process that opened it.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

New York News Daily is a media business in New York. Rachel Cohen looks after its IT and cloud work. They count money in USD and run their AWS resources in the us-east-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 10

Easy Create a team group

Groups let you give the same access to many users at once.

Create a group named nynewsdaily-dev.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Switch to another user

Testing as the real user shows what they can and cannot do.

Switch to user rachel with a full login environment.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Protect an SSH key file

SSH refuses to use a key file that other users can read.

Make nynewsdaily-key.pem readable only by its owner and nobody else (no write).

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Set normal web file permissions

Web files should be readable by everyone but writable only by the owner.

Give index.html the permissions: owner read+write, group read, others read (use numbers).

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Set a user's password

A new user cannot log in with a password until one is set.

Set the password for user rachel.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Give a folder to the web server user

If nginx does not own the upload folder, uploads fail with "permission denied".

Make user nginx and group nginx the owners of /var/www/nynewsdaily/uploads and everything inside.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Give a user sudo rights

On Amazon Linux, members of the wheel group can use sudo.

Add rachel to the wheel group without removing their other groups.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Fix permissions on a whole folder

Folders need the x bit so the web server can enter them. -R applies it to everything inside.

Set permissions 755 on /var/www/nynewsdaily and everything inside it.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Create a user with a home folder

Each person should have their own login, with their own home folder and shell.

Create the user rachel with a home folder and /bin/bash as the login shell.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Permission number

Key files must be private.

What chmod number gives the owner read+write and nobody else anything?

  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Quick revision cards

Revise this lesson in two minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens its lesson.

Comparison card: IAM user vs Linux user. IAM user: A person or app in your AWS account. Linux user: An account inside one server's operating system.
Comparison: IAM user vs Linux user · Download PNG
Comparison card: touch vs sudo touch. touch: Creates an empty file as you. sudo touch: Creates an empty file as root.
Comparison: touch vs sudo touch · Download PNG
Revision card: Owner and group in ls -l. Permissions mean nothing until you know who the owner and group are. Every file has one owner (u) and one group (g); everyone else is others (o). Change with chown and chgrp (needs sudo). ls -l:
Revision card: Owner and group in ls -l · Download PNG
Revision card: Share files with a group. A team must edit the same files without using one shared login. Create a group, add users, give the folder to the group with write permission. groupadd, usermod -aG, chgrp, chmod g+w. Setup:
Revision card: Share files with a group · Download PNG
Revision card: whoami, who and w. On a shared server you must know who you are and who else is in. whoami = your user. who = logged-in users. w = users plus what they are running. Run all three after su to see the difference. After sudo su:
Revision card: whoami, who and w · Download PNG
Revision card: Run a script: the x bit. A new script gives "Permission denied" when you run it. Files are not executable by default. chmod +x adds the x (execute) bit. Add the bit, run with ./ ; stop an endless loop with Ctrl+C. Commands:
Revision card: Run a script: the x bit · Download PNG
Interview card: Why should a team not share one ec2-user login?. Nobody can tell who did what, and removing one person means changing the key for all. Separate users give accountability and least privilege. One user per person, sudo only for admins.
Interview card: Why should a team not share one ec2-user login? · Download PNG
Interview card: Why do new files show 664 instead of 644?. The umask for normal users is 002, so the group keeps write. Each user has a private group, so group write is still safe. umask shows it:
Interview card: Why do new files show 664 instead of 644? · Download PNG
Interview card: When should you use sudo, and when not?. Use it for system changes: installs, /etc, services. Not for your own files. Files made with sudo become root-owned and you cannot edit them later. sudo touch a.txt › owner root.
Interview card: When should you use sudo, and when not? · Download PNG

More cards: Ravi Sir's Cards.