> For the complete documentation index, see [llms.txt](https://klenin.gitbook.io/rememberable/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://klenin.gitbook.io/rememberable/devops/oc/linux.md).

# Linux

## The Basics

<details>

<summary>Basic commands</summary>

* `sudo apt update && sudo apt upgrade -y`
* `sudo apt install net-tools`

</details>

<details>

<summary>Systemctl</summary>

* `sudo systemctl restart <systemd-process-name>`
* `sudo systemctl stop <systemd-process-name>`
* `sudo systemctl status <systemd-process-name>`
* `sudo journalctl -f -u <systemd-process-name>`
* `sudo systemctl enable /etc/systemd/system/<systemd-process-name>`
* `sudo systemctl disable /etc/systemd/system/<systemd-process-name>`

</details>

<details>

<summary>Linux user</summary>

* `sudo chown -R ubuntu:ubuntu /var/www`
* `sudo visudo` \
  `ubuntu ALL=(ALL) NOPASSWD:ALL`

</details>

<details>

<summary>Find, files</summary>

* `find . -mount -type f -size +1G 2>/dev/null`
* `find . -mount -type f -size +100M 2>/dev/null`
* `sudo du -a / | sort -n -r | head -n 20`

</details>

{% hint style="info" %}
**Important!** When you enable **Firewall** and if you want to connect on your server by ssh, you must allow it in firewall 22 port
{% endhint %}

<details>

<summary>Firewall</summary>

* `sudo apt install ufw -y`
* `sudo ufw status`
* `sudo ufw enable`
* `sudo ufw disable`
* `sudo ufw allow OpenSSH`
* `sudo ufw allow 22/tcp`
* `sudo ufw allow 80/tcp`
* `sudo ufw allow 443/tcp`
* `sudo ufw allow 3306`
* `sudo ufw allow 'Nginx HTTP'`
* `sudo ufw app list`

</details>

<details>

<summary>Remote connection</summary>

* `scp readme.txt user@192.168.0.1:/home/user/temp`
* `scp -r -i ~/.ssh/digitalocean readme.txt user@192.168.0.1:/home/user/temp`

</details>

<details>

<summary>Configs</summary>

* `wget -qO- eth0.me` - get ip server
* `ifconfig | grep "inet " | grep -v 127.0.0.1` - To get access to your localhost you can via using same wifi network
* `ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'` - Get your local IP

</details>

<details>

<summary>Crontab</summary>

Useful [link](https://crontab.guru/)

* `0 * * * *` - Every hour

</details>

<details>

<summary>Aliases</summary>

Add alias:

`sudo nano ~/.bashrc`\
`alias p='df -h'`

</details>

<details>

<summary>Gpg keys</summary>

Install gpg command

* `gpg --full-gen-key` - generate key

All keys in `~/.gnupg/openpgp-revocs.d/`

</details>

<details>

<summary>Ssh</summary>

Create ssh key and paste it in server:

1. `ssh-keygen -t rsa` - generate an ssh key (type file path and name if you want)
2. Or `ssh-keygen -t rsa -f ~/.ssh/example` - generate an ssh key (type file path and name if you want)
3. `pbcopy < ~/.ssh/id_rsa.pub` - copy file contents
4. Paste .pub content to server

Connection to server:

```
ssh <username>@<ip_address> 
```

```
ssh <username>@<ip_address> -i ~/.ssh/id_rsa
```

</details>

* `sudo lsof -i -P | grep LISTEN | grep :$PORT` - Check all ports
