Linux
Setup
Install Firewall
- Install
sudo apt install ufw numbered
- Configuration
- Check status & list configuration
sudo ufw status
- Allow a port
sudo ufw allow PORT
- Remove an allowance
sudo ufw remove PORT
- Rate limit a port (>6 connections within 30 sec)
sudo ufw limit PORT
- Check status & list configuration
- Verify
- Check added rules
sudo ufw show added
- Check added rules
- Enable
sudo ufw enable
Install FTP server
sudo apt install vsftpd
sudo nano /etc/vsftpd.conf
to edit configurationsudo ufw allow 21
sudo systemctl restart vsftpd
Power Management
- On a laptop: disable standby on lid close: in
/etc/systemd/logind.conf
, uncomment and changeHandleLidSwitch=ignore
Check temperatures:
sudo apt install lm-sensors
sudo apt-get install lm-sensors
sudo /etc/init.d/kmod start
sensors
Format & mount a USB stick
- Several options to see devices
sudo blkid
to locate block devicessudo lsblk
to list mounted block devicesls /dev
to check where the usb stick is mounted
sudo fdisk /dev/sda
if the usb stick is onsda
p
to list existing partitiong
to create a new GPT partition table oro
for a DOS partition tablen
to create a new partitionw
write to disk and exit
sudo mkfs.ext4 /dev/sda1
to create a ext4 partitionsudo mkdir /media/usbdrive
to create a directory that will host the partition- Choose
/mnt
for temporary mounts - Choose
/media
for automatics mounts
- Choose
sudo mount /dev/sda1 /media/usbdrive -o umask=000
to mount the usb key with all user accesssudo umount /dev/sda1
to unmount- If you want to make it permanent
- Edit
sudo nano /etc/fstab
- Add a line
/dev/sda1 /media/usbdrive ext4 defaults 0 0
- (Check how fstab works here)
- Edit
Test read/write speed
sync; dd if=/dev/zero of=tempfile bs=1M count=256; sync
: write to tempfile 256 Mbsudo /sbin/sysctl -w vm.drop_caches=3
: clear the cachedd if=tempfile of=/dev/null bs=1M count=256
: read tempfile
Tips & Tricks
- System variables
id $user
to get user PUID & GUID
- Files & filesystem
ncdu
to tree files & folder, and explore space takenfsck /dev/sda1
to check for partition corruption
- Date & Time
timedatectl
to checksudo timedatectl set-timezone TZ
Usability
Screen Terminal Multiplexer
- Start
screen
- List sessions ID
screen -ls
- In a session:
- Detach
CTRL+A d
- Reattach
screen -r session_ID
- Detach
Maintenance
- Update packages
sudo apt update && sudo apt upgrade
- Check free disk space
df -h
- Check system stats
htop
for processesnmon
for the whole system
Recover
Check logs
- System messages:
cat /var/log/messages | tail -n 50
Bootloader
Try Super Grub2 Disk
Services with systemctl
sudo systemctl status SERVICE
- Service management
sudo systemctl restart SERVICE
sudo systemctl start SERVICE
sudo systemctl stop SERVICE
sudo systemctl kill SERVICE
- Service enable/disable
sudo systemctl enable SERVICE
sudo systemctl disable SERVICE
sudo systemctl is-enabled SERVICE