> 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-1-solution.md).

# Assignment 1 - Solution

**Author:** Mrinal Ghimire

## 1. SSH to the Server

### Objective

Securely connect to a Linux server using SSH authentication with the **ubuntu** user by using an RSA public/private key pair.

{% stepper %}
{% step %}

### Generate an RSA Key Pair (Local Machine)

```bash
ssh-keygen -t rsa -b 4096
```

Press **Enter** to save the key in the default location (`~/.ssh/id_rsa`).

This creates:

* `~/.ssh/id_rsa` (Private Key - keep secret)
* `~/.ssh/id_rsa.pub` (Public Key - copy to the server)
  {% endstep %}

{% step %}

### View the Public Key

```bash
cat ~/.ssh/id_rsa.pub
```

Copy the entire output.
{% endstep %}

{% step %}

### Add the Public Key to the Remote Server

Login to the remote server using a password (or console access):

```bash
ssh ubuntu@192.168.1.20
```

Create the SSH directory if it doesn't exist:

```bash
mkdir -p ~/.ssh
chmod 700 ~/.ssh
```

Open the authorized keys file:

```bash
nano ~/.ssh/authorized_keys
```

Paste the copied public key, save, then set permissions:

```bash
chmod 600 ~/.ssh/authorized_keys
```

{% endstep %}

{% step %}

### Connect Using SSH

From your local machine:

```bash
ssh ubuntu@192.168.1.20
```

#### Verify

```bash
whoami
hostname
```

Expected user:

```
ubuntu
```

{% endstep %}
{% endstepper %}

### Why SSH Keys?

* More secure than passwords
* Password-less authentication
* Resistant to brute-force attacks
* Standard practice for Linux server administration

## 2. System Information

### a) CPU Cores

```bash
lscpu
nproc
```

### b) Memory

```bash
free -h
```

### c) Total Disk Space

```bash
df -h
```

### d) Disk Partitions

```bash
lsblk
```

### e) Private IP

```bash
hostname -I
```

### f) Hostname

```bash
hostname
```

### g) OS Name

```bash
cat /etc/os-release
```

### h) Kernel Version

```bash
uname -r
```

## 3. Check Cron

```bash
systemctl status cron
crontab -l
cat /etc/crontab
```

Purpose: Schedule automated tasks like backups, updates and log rotation.

## 4. Listening Ports

```bash
sudo ss -tulnp
```

## 5. Check Web Server

```bash
systemctl status nginx
systemctl status apache2
curl localhost
```

## 6. Find Users

```bash
awk -F: '$3>=1000 {print $1}' /etc/passwd
```

## 7. Ubuntu User Status

```bash
sudo chage -l ubuntu
sudo passwd -S ubuntu
```

## 8. Find `.sh` Files

```bash
find / -type f -name "*.sh" 2>/dev/null
```

## 9. Synchronize Time

```bash
sudo apt update
sudo apt install chrony -y
sudo systemctl enable chrony
sudo systemctl start chrony
sudo timedatectl set-timezone Asia/Kathmandu
timedatectl
```

## 10. Backup Script

```bash
grep -Ri "/data" /etc /home 2>/dev/null
```

Example:

```bash
#!/bin/bash
DATE=$(date +%F)
tar -czf /backup/data-$DATE.tar.gz /data
```

## 11. CPU Usage

```bash
top
htop
mpstat
```

Consider CPU utilization, load average, I/O wait, idle time and CPU cores.

## 12. Last Boot

```bash
who -b
uptime -s
```

## 13. Update System

```bash
sudo apt update
apt list --upgradable
sudo apt upgrade
sudo apt autoremove
```

## 14. Permissions

```bash
ls -ld /test
getfacl /test
```

## 15. Save Documentation

```bash
mkdir -p /home/ubuntu/Mrinal
nano /home/ubuntu/Mrinal/revision.txt
```


---

# 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-1-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.
