> For the complete documentation index, see [llms.txt](https://mrinalghimire.com.np/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mrinalghimire.com.np/assignment-1/assignment-2-solution.md).

# Assignment 2 - Solution

**Author:** Mrinal Ghimire

***

## 1. Create User Accounts

### Objective

Create:

* Group **testing**
* User **natasha** (secondary group: testing)
* User **harry** (secondary group: testing)
* User **sarah** (no interactive shell and not a member of testing)

All users should have the password:

```
flectrag
```

***

### Step 1: Create Group

```bash
sudo groupadd testing
```

#### Verify

```bash
getent group testing
```

***

### Step 2: Create Users

#### Natasha

```bash
sudo useradd -m -G testing natasha
```

#### Harry

```bash
sudo useradd -m -G testing harry
```

#### Sarah

```bash
sudo useradd -m -s /usr/sbin/nologin sarah
```

> On some distributions the shell may be `/sbin/nologin`.

***

### Step 3: Set Password

```bash
echo "natasha:flectrag" | sudo chpasswd
echo "harry:flectrag" | sudo chpasswd
echo "sarah:flectrag" | sudo chpasswd
```

***

### Verify

```bash
id natasha
id harry
id sarah
```

Expected:

* Natasha → member of testing
* Harry → member of testing
* Sarah → not in testing

***

## 2. Create a Collaborative Directory

### Objective

Create

```
/home/admins
```

Requirements

* Group owner = testing
* Members of testing can read, write and enter
* Others have no access
* Files inherit the testing group automatically

***

### Step 1

```bash
sudo mkdir /home/admins
```

***

### Step 2

Change group ownership.

```bash
sudo chgrp testing /home/admins
```

***

### Step 3

Set permissions and SGID bit.

```bash
sudo chmod 2770 /home/admins
```

#### Explanation

* 2 → SGID
* 7 → Owner rwx
* 7 → Group rwx
* 0 → Others no permission

Verify

```bash
ls -ld /home/admins
```

Expected

```
drwxrws---
```

***

## 3. Configure /var/tmp/fstab Permissions

### Copy File

```bash
sudo cp /etc/fstab /var/tmp/fstab
```

***

### Set Owner

```bash
sudo chown root:root /var/tmp/fstab
```

***

### Remove Execute Permission

```bash
sudo chmod 644 /var/tmp/fstab
```

***

### Configure ACL

Allow natasha read/write

```bash
sudo setfacl -m u:natasha:rw /var/tmp/fstab
```

Deny harry

```bash
sudo setfacl -m u:harry:--- /var/tmp/fstab
```

Verify

```bash
getfacl /var/tmp/fstab
```

#### Why ACL?

Standard Linux permissions cannot allow one specific user while denying another. ACLs provide fine-grained permissions.

***

## 4. Configure a Cron Job

Login as natasha.

```bash
su - natasha
```

Open cron.

```bash
crontab -e
```

Add

```cron
23 14 * * * /bin/echo hello
```

Save.

Verify

```bash
crontab -l
```

#### Explanation

```
Minute Hour Day Month Weekday Command
```

```
23 14 * * *
```

means every day at **2:23 PM**.

***

## 5. Create a Compressed Archive

### Objective

Archive

```
/tmp
```

into

```
/var/tmp/tmp.tar.bz2
```

using **bzip2** compression.

***

### Command

```bash
sudo tar -cjf /var/tmp/tmp.tar.bz2 /tmp
```

#### Explanation

* c → create archive
* j → bzip2 compression
* f → output file

***

### Verify

```bash
ls -lh /var/tmp/tmp.tar.bz2
```

List archive contents

```bash
tar -tjf /var/tmp/tmp.tar.bz2
```

***

## Verification Commands

### Users

```bash
id natasha
id harry
id sarah
```

### Group

```bash
getent group testing
```

### Directory

```bash
ls -ld /home/admins
```

### ACL

```bash
getfacl /var/tmp/fstab
```

### Cron

```bash
crontab -l
```

### Archive

```bash
ls -lh /var/tmp/tmp.tar.bz2
```

***

## Conclusion

In this assignment, we successfully:

* Created users and groups
* Managed group memberships
* Configured a collaborative directory using SGID
* Applied file permissions and ACLs
* Scheduled a cron job
* Created a compressed tar archive using bzip2

These are essential Linux administration tasks commonly performed by system administrators in production environments.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mrinalghimire.com.np/assignment-1/assignment-2-solution.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
