---
# System prepended metadata

title: linux mid exam ubuntu
tags: [linux]

---

# unix mid exam ubuntu

## Mounting a new partition

first, add disk to VM

use fdisk to partition

```shell
$ sudo fdisk /dev/sdb
```

press `n` to create a new storage

then, press`w` to save ur change

use `mkfs` 

```shell
$ sudo mkfs -t ext4 /dev/sdb1
```

> [!Tip]
> **`mkfs`** is the abbrevation of **M**a**k**e **F**ile **S**ystem

finally, use `mount` to mount the disk to dir

```shell
$ sudo mount /dev/sdb1 /home/mnt1
```

to check if mounting successful

```shell
$ lsblk
```

> [!Tip]
> **`lsblk`** is the abbrevation of **L**i**s**t **Bl**oc**k**

### Auto mounting on startup

add disk uuid to the `/etc/fstab`

> [!Tip]
> **`fstab`** is the abbrevation of **F**ile **S**ystem **Tab**le

find disk uuid

```shell
$ lsblk -f
```

copy uuid and go to `/etc/fstab`

```shell
$ sudo vim /etc/fstab
```

if u have not installed `vim` yet, use apt command

```shell
$ sudo apt install vim
```

add a new line 

```
UUID=<uuid> <mount_dir> ext4 default 0 1
```

then, press `Escape` and type `:wq` 

in order to check whether disk is auto mounting or not, we need to reboot our system

```shell
$ sudo reboot
```

or shutdown and restart 

```shell
$ sudo shutdown now
```

finally, use `lsblk` to check this is mounting or not

## Create new user

```shell
$ sudo adduser b
```

## Add user to sudoers

```shell
$ sudo visudo
```

:::spoiler 📝 Example: give user b `apt` permission

1. run visudo
2. add b to allow apt command

```diff
  root ALL=(ALL) ALL
+ b ALL=(ALL) NOPASSWD: /usr/bin/apt
```

:::

:::spoiler 📝 Example: give user multiple command permission

1. run visudo
2. add b to allow `apt` and `vim` command

```diff
  root ALL=(ALL) ALL
+ b ALL=(ALL) NOPASSWD: /usr/bin/apt, /usr/bin/vim
```

:::

to check self permission

```shell
$ sudo -l
```

if not have any sudo permission, u cannot do this

search command path

```shell
$ which apt
```

## Change File Permissions

create a new folder under `/home` folder

```shell
$ sudo mkdir share
```

and change folder to uself

```shell
$ sudo chown 'u name':'u name or share grp name' /share
```

and craete a cpp file

```shell
$ cd share
$ vim a.cpp
$ g++ ./a.cpp -o a
```

give file permission

```shell
$ chmod g+w /share/a.cpp
$ chmod o+xs /share/a
```

| scope          | operator | permission |
| -------------- | -------- | -------- |
| `u` file owner<br>`g` group<br>`o` others<br>`a` all | `+` add<br>`-` remove<br>`=` set | `r` read<br>`w` write<br>`x` execute<br>`s` setuid |

switch to user b and check it

![91tiRtwMXsL](https://hackmd.io/_uploads/SJxJWxKWke.jpg)

good luck