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 vsftpdsudo nano /etc/vsftpd.confto edit configurationsudo ufw allow 21sudo systemctl restart vsftpd
Related softwares¶
- Cron: Job scheduler
Cockpit - Remote administration of server¶
sudo apt-get install cockpitand with:cockpit-machinesfor KVMcockpit-dockerfor Docker
sudo ufw allow 9090sudo systemctl restart cockpit.socket- If you cannot update packages,
network managermay be in use, check withnmcli dsudo systemctl disable network-manager.servicesudo 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
timedatectlto checksudo timedatectl set-timezone TZ- See also
- Screen terminal multiplexer
Command-line kung-fu¶
lessto redirect output to a pagerwatchto watch regularly an output| grep xto pipe to grep which is going to select lines withx^a163bcclearto clear the command line- Check this Ars introduction about redirection,
grep,sed,awk. echo $?to inspect program exit codedu -hlike disk usage to check size of directorywhich abcto check where theabcbinary 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 capabilities
lscpu- Can also list active mitigations
- Check system stats
htopfor processesnmonfor 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 SERVICEsudo systemctl start SERVICEsudo systemctl stop SERVICEsudo systemctl kill SERVICE
- Service enable/disable
sudo systemctl enable SERVICEsudo systemctl disable SERVICEsudo systemctl is-enabled SERVICE
- Services mask/unmask
sudo systemctl unmask SERVICEsudo systemctl mask SERVICE
- Service status
sudo systemctl list-timerssudo 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 / park
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.zipto unzipunzip -l ./file.zipto list files in the zip (and the validity of the zip)
tar -xvf file.tar.gzto extract tarball and zip (xfor extract,vfor verbose,ffor file)bunzip2 filename.bz2to extract a bz2 filefind / -name filenameto find filename in entire system (/) or active folder (.), andsudoto avoid permissions problemscp -ato 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-toolsto install required toolsudo guestmount -a /var/lib/libvirt/images/IMAGE.qcow2 -m DEVICE --ro /mnt/FOLDERDEVICEbeing the partition within this image. Make it bogus so a list will be shown--roif 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 upfor 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 wlanto list statusrfkill unblock wlanto 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 ato list network adapterssudo sysctl -w net.ipv6.conf.ADAPTER.disable_ipv6=1to disable (temporary) IPv6, with ADAPTER likebr6- Add the above to
/etc/sysctl.confand apply withsudo sysctl -p
Set up Let's Encrypt with Cloudflare DNS¶
- Source
- See this documentation on Cloudflare certbot
cloudflare.inican be placed in/etc/cloudflared- Define proper permission with
chmod 400
- Steps
sudo snap install --classic certbot certbot-dns-cloudflareYou may need to proceed with additional commands as explained in the consolesudo ln -s /snap/bin/certbot /usr/bin/certbotsudo 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 ^98e6b4
useradd USERNAMEadd a new user- With a Home directory:
-m - Remove shell access:
--shell /bin/false
- With a Home directory:
usermod -L USERNANEto lock accesspasswd USERNAMEdefine a passwordid $userto get user PUID & GUID
- Groups
usermod -a -G GROUP $USERto add self to GROUPcat /etc/groupto 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/ visudocan 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 NEWHOSTNAMEand update/etc/hosts - Check all installed packages, sorted by size:
dpkg-query -W -f='${Installed-Size;8} ${Package}\n' | sort -n
Hardware-related¶
- Sometime
rebootis 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-sensorssudo apt-get install lm-sensorssudo /etc/init.d/kmod startsensors
- Check status & stats about battery
- List paths
upower -e - Get status
upower -i <path>
- List paths
- Plan a reboot:
shutdown -r 0:00to 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