#homelab #Linux #CheatSheet
## General
Will be based mostly on Debian, as this is the distro I am currently using in my homelab.
## File Locations
| Service/ File description | Path |
| ---------------------------- | -------------------------- |
| NIC configuration | /etc/networking/interfaces |
| DNS Configuration | /etc/resolv.conf |
| bashrc file for aliases etc. | ~/.bashrc |
## Services
| Service Name | Description |
| ------------------ | ----------------------------------------------------------- |
| Networking.service | for general networking, restart if IP changes etc. are done |
| | |
## Cheat-sheet
### General
Update
1. Pacman
`sudo pacman -Syu`
2. yay
`yay` or `yay -Syu`
See version of OS:
`cat /etc/os-release`
See who is logged in:
`who`
Add new user:
`useradd -m $username`
Change shell of user to bash:
`sudo chsh -s /bin/bash $username`
Add user to sudo:
`usermod -aG sudo username`
Apt Sources List:
`sudo nano /etc/apt/sources.list`
Different information about categories:
```bash
lscpu #information about cpu
lsblk #information about block devices
lspci #information about pci devices
lsusb #information about usb devices
```
### SSH
Generate SSH key:
`ssh-keygen -t ed25519 -C "Name"`
-t for type, ed25519 is safer than the default
-C for a comment
Copy public SSH key to remote host:
`ssh-copy-id username@remote_host`
Will be added to remote host's:
`~/.ssh/authorized_keys`
Can also be added manually here.
Disable password authentication:
```bash
sudo vi /etc/ssh/sshd_config
```
### Git
Initial configuration of local git:
````
git config --global user.name "Robin Sponar"
git config --global user.email "
[email protected]"
````
Clone remote git repo to current directory:
`git clone
[email protected]:rsponar/Ansible.git`
List changes since last push:
`git status`
Make changes part of commit:
`git add README.md`
Commit changes:
`git commit -m "commit message"`
Push changes to remote repository:
`git push`
Will default to the selected branch.
### Network
See which ports are used by which services:
`sudo lsof -i -P -n | grep LISTEN`
Test http/https connectivity:
`curl -i http://log-01.sponar.local:9200`
Set static IP:
`sudo nano /etc/network/interfaces`
```bash
# The primary network interface
auto ens192
iface ens192 inet static
address 192.168.178.91
netmask 255.255.255.0
gateway 192.168.178.1
dns-nameservers 192.168.178.85 8.8.8.8
```
(Don't need to indent)
`sudo systemctl restart networking`
Change hostname:
`sudo hostnamectl set-hostname $hostname`
Alternative:
in `/etc/hosts`
and `/etc/hostname`
After changing, reboot.
Add NTP Server:
1. `sudo apt install ntp`
2. `sudo nano /etc/ntp.conf`
3. Remove any lines containing "pool" or "server"
4. Add a new line `server opn-01.sponar.local`
5. Restart services `sudo systemctl restart ntp`
6. Verify if NTP is working `ntpq -p`
7. (Optional) Force resync time
```bash
sudo service ntp stop
sudo ntpd -gq
sudo service ntp start
```
Lists local IP addresses.
Lists current route, needs to have a default route:
`ip route`
Uses DNS server to look up google.com:
`dig @dnsserver google.com`
Host file:
`/etc/hosts`
Shows the order of DNS lookups (files, DNS, etc.):
`/etc/nsswitch.conf`
See current nameserver (do not edit file, managed by network manager or other services):
`/etc/resolv.conf`
Interface file for each NIC:
`/etc/network/interfaces`
Network configuration files in .yaml format on newer distributions (indents matter!):
`/etc/netplan`
Applies new configuration:
`sudo netplan apply`
For graphical configuration on newer Ubuntu systems:
`sudo nmtui`
### Modules
Load module into running kernel:
`modprobe [modname]`
List all running modules:
`lsmod`
Remove module from running kernel:
`rmmod`
Update list of modprobes (after adding a module e.g.):
`depmod`