Is an Operating System for all sort of things. In this database, I refer to Unix via Linux
Please note: I mainly use Ubuntu Server or Debian, so your mileage may vary with other distros.
Setup¶
- On a laptop: disable standby on lid close: in
/etc/systemd/logind.conf
, uncomment and changeHandleLidSwitch=ignore
Related¶
Install FTP server¶
sudo apt install vsftpd
sudo nano /etc/vsftpd.conf
to edit configurationsudo ufw allow 21
sudo systemctl restart vsftpd
Related softwares¶
- Cron: Job scheduler
Cockpit - Remote administration of server¶
sudo apt-get install cockpit
and with:cockpit-machines
for KVMcockpit-docker
for Docker
sudo ufw allow 9090
sudo systemctl restart cockpit.socket
- If you cannot update packages,
network manager
may be in use, check withnmcli d
sudo systemctl disable network-manager.service
sudo systemctl stop network-manager.service
Advanced configuration¶
- See this guide to change port. Create file and directory if needed.
- Configuration file is
/etc/cockpit/cockpit.conf
, not created by default - see reference -
Setup with Cloudflare Tunnel - Based on this blog post.
- Setup a Let's Encrypt certificate below
-
Setup a copy script - See example in Nextcloud
```sh
!/bin/sh¶
FQDN="DOMAIN.COM"
echo "SSL certificates renewed" cp /etc/letsencrypt/live/$FQDN/fullchain.pem /etc/cockpit/ws-certs.d/$FQDN.crt cp /etc/letsencrypt/live/$FQDN/privkey.pem /etc/cockpit/ws-certs.d/$FQDN.key chown cockpit-ws:cockpit-ws /etc/cockpit/ws-certs.d/$FQDN.crt /etc/cockpit/ws-certs.d/$FQDN.key
echo "Restarting Cockpit" systemctl restart cockpit ```
-
Setup
/etc/cockpit/cockpit.conf
```conf [WebService] Origins = https://URL:PORT
ProtocolHeader = X-Forwarded-Proto¶
AllowUnencrypted = false
[Session] IdleTimeout = 10 ```
-
Setup Cloudflare Tunnel and Access
Install on VirtualBox¶
See VirtualBox page.
Tips & Tricks¶
- Date & Time
timedatectl
to checksudo timedatectl set-timezone TZ
- See also
- Screen terminal multiplexer
Command-line kung-fu¶
less
to redirect output to a pagerwatch
to watch regularly an output| grep x
to pipe to grep which is going to select lines withx
^a163bcclear
to clear the command line- Check this Ars introduction about redirection,
grep
,sed
,awk
. echo $?
to inspect program exit codedu -h
like disk usage to check size of directorywhich abc
to check where theabc
binary is stored- See also:
- Vi - text editor
Install a software on system¶
wget the latest release of the chosen software
sudo apt-get install # dependencies
sudo mkdir -p /opt/software_name
mv # move the app to /opt/software_name
sudo chmod +x /opt/software_name/executable # make the executable executable
sudo ln -s /opt/software_name/executable /usr/bin/executable # create a simlink
CPU & Processes¶
- Check system stats
htop
for processesnmon
for the whole system
- Health
- Check CPU frequency
cat /proc/cpuinfo
- Check CPU frequency
- System information
dmidecode
- Do a stress test with full CPU utilization:
for i in $(seq $(getconf _NPROCESSORS_ONLN)); do yes > /dev/null & done
Services with systemctl¶
- 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
- Services mask/unmask
sudo systemctl unmask SERVICE
sudo systemctl mask SERVICE
- Service status
sudo systemctl list-timers
sudo systemctl status SERVICE
Disk & Data¶
- Current working directory:
pwd
- Check free disk space
df -h
- Tree file & folder with space taken
ncdu
- Check for partition corruption
fsck /dev/sdaXX00
- Stop a (USB) disk
- Unmount
sudo umount /dev/sdXX
- Spin down
sudo hdparm -Y /dev/sdXX
- Unmount
- Erase a disk
sudo dd if=/dev/urandom of=/dev/sdXX bs=10M
- Source - Check what is mounted where:
findmnt
- List all block devices:
lsblk
- TRIM a SSD:
sudo /sbin/fstrim -av
View SMART disk data¶
Source
1. Install smartmontools
1. View SMART data & status sudo smartctl -i /dev/sdXX
1. Find estimate & current SMART test sudo smartctl -a /dev/sdXX
1. Launch a test: sudo smartctl -t short /dev/sdXX
* Possible options instead of short
:
* long
* conveyance
(after transport) for ATA disks
* If the HDD go to sleep (especially true for USB ones), try the following:
```bash
while true; do
dd if=/dev/sdXX iflag=direct count=1 of=/dev/null
sleep 60
done
```
- Read the result
sudo smartctl -l selftest /dev/sdXX
Test read/write speed¶
Source
1. sync; dd if=/dev/zero of=tempfile bs=1M count=256; sync
: write to tempfile 256 Mb
1. sudo /sbin/sysctl -w vm.drop_caches=3
: clear the cache
1. dd if=tempfile of=/dev/null bs=1M count=256
: read tempfile
Format & mount a USB stick¶
Files¶
zip -r directoryname.zip ./
to zip current directoryunzip ./file.zip
to unzipunzip -l ./file.zip
to list files in the zip (and the validity of the zip)
tar -xvf file.tar.gz
to extract tarball and zip (x
for extract,v
for verbose,f
for file)bunzip2 filename.bz2
to extract a bz2 filefind / -name filename
to find filename in entire system (/) or active folder (.), andsudo
to avoid permissions problemscp -a
to copy everything (-Archive
)find /path/to/folder -name "thing to search"
to find something- Edit a text file on GUI:
mousepad
Virtual Systems: Mount QCoW2¶
sudo apt install libguestfs-tools
to install required toolsudo guestmount -a /var/lib/libvirt/images/IMAGE.qcow2 -m DEVICE --ro /mnt/FOLDER
DEVICE
being the partition within this image. Make it bogus so a list will be shown--ro
if you only want read-only
sudo guestunmount /mnt
Network & Internet¶
- View current information (IP, netmask, ...)
ifconfig
- Assign an IP to a network
sudo ifconfig wlan0 192.168.65.1 netmask 255.255.255.0 up
for instance
- Assign an IP to a network
- Edit network configuration
- with netplan
/etc/netplan/00-installer-config.yaml
- with netplan
- Check Wi-Fi adapter status:
rfkill list wlan
to list statusrfkill unblock wlan
to unblock
- Check used ports:
ss -tunlp
Activate IPv6¶
- Edit
/etc/network/interfaces
- Add
iface eth0 inet6 dhcp
- more options here - Apply changes
service networking restart
Disable IPv6¶
ip a
to list network adapterssudo sysctl -w net.ipv6.conf.ADAPTER.disable_ipv6=1
to disable (temporary) IPv6, with ADAPTER likebr6
- Add the above to
/etc/sysctl.conf
and apply withsudo sysctl -p
Set up Let's Encrypt with Cloudflare DNS¶
- Source
- See this documentation on Cloudflare certbot
cloudflare.ini
can be placed in/etc/cloudflared
- Define proper permission with
chmod 400
- Steps
sudo snap install --classic certbot certbot-dns-cloudflare
You may need to proceed with additional commands as explained in the consolesudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini -d <EXAMPLE.COM>
- Automated renewal should be set up by the snap, check
systemctl list-timers
Users & Groups¶
- Users
useradd USERNAME
add a new user- With a Home directory:
-m
- Remove shell access:
--shell /bin/false
- With a Home directory:
usermod -L USERNANE
to lock accesspasswd USERNAME
define a passwordid $user
to get user PUID & GUID
- Groups
usermod -a -G GROUP $USER
to add self to GROUPcat /etc/group
to list all groups
- Setup SFTP for without Shell: nice tutorial from Digital Ocean
- Act as a user:
sudo -u USERNAME command
- Mails are stored in
/var/mail/
Scripts execution¶
- Can be stored in
/usr/sbin/user_scripts/
visudo
can help defining a script that can be run as sudo<user> ALL=(ALL) NOPASSWD: /path/to/script.sh
- Don't forget to
- Set the script as executable with
sudo chmod +x /path/to/script.sh
- Prevent edition with
chmod u-w,g-w /path/to/script.sh
(here we remove user and group write)
- Set the script as executable with
OS-related¶
- Know which OS, flavor, distro, distribution or version you are running
cat /etc/os-release
- Install fonts, check package
fonts-liberation
- can help you to fixFontconfig error: Cannot load default config file
- Change host name:
hostnamectl set-hostname NEWHOSTNAME
and update/etc/hosts
- Check all installed packages, sorted by size:
dpkg-query -W -f='${Installed-Size;8} ${Package}\n' | sort -n
Hardware-related¶
- Sometime
reboot
is not accessible ... then usesystemctl reboot
- Test RAM with
sysbench --test=memory --memory-block-size=1M --memory-total-size=1000G
- Check PCIe speed:
lspci -vvvv
- Reset an USB device:
usbreset
Power & Battery¶
- Check system temperature
sudo apt install lm-sensors
sudo apt-get install lm-sensors
sudo /etc/init.d/kmod start
sensors
- Check status & stats about battery
- List paths
upower -e
- Get status
upower -i <path>
- List paths
- Plan a reboot:
shutdown -r 0:00
to restart at midnight for instance
BIOS¶
- Check BIOS version
sudo dmidecode | less
Display, Media & Sound¶
- Instead of changing the DPI to 125% which makes things weird, enable Large Text in Accessability
Security¶
- Source: OVH, DigitalOcean, DigitalOcean
- Change all account passwords
- Regarding SSH
- Regarding network
- Configure firewall like
ufw
- Configure fail2ban
- Configure an Intrusion Detection System - Example
- Configure firewall like
- Disable unneeded services - Example,
sudo ss -atpu
- Implement unattended/automated upgrades and livepatch - Example
- Regularly
- Update software
- Check logs
- Check for malware - Example:
maldet
- Make backups
Recover¶
Check logs¶
- System messages:
cat /var/log/messages | tail -n 50
Bootloader¶
Try Super Grub2 Disk
KVM - Virtual Machines¶
Related¶
TABLE file.path as "Location"
FROM [[]]
SORT file.name ASC
SORT file.path ASC