Debian
Package installation
dpkg
Install a package from a .deb file
sudo dpkg -i PACKAGE_NAME
Remove a package
sudo dpkg -r PACKAGE_NAME
Purge a package
This removes the package and all its dependencies
sudo dpkg -P PACKAGE_NAME
List installed packages
dpkg -l
Lookup information on a hostname
dig domain_to_lookup
Cron jobs
Edit cronjobs
To edit cron jobs use crontab -e
. The syntax is as follows
[Minute] [hour] [Day_of_the_Month] [Month_of_the_Year] [Day_of_the_Week] [command]
So a valid cron job could look like this, runs everyday at 2am
0 2 * * * /bin/sh backup.sh
To run on an interval (in this case every 10 minutes), use
*/10 * * * * /scripts/monitor.sh
List cron jobs
crontab -l
File movement
Copy files from directory into another
cp -a /source/. /dest/
Move files into parent directory
mv subfolder/* .
Web hosting
Give permissions to a user to use /var/www for static files
See this post for a good summary of things to watch for. For static files there shouldn't be anything that needs to be written by the webserver.
sudo gpasswd -a "$USER" www-data
sudo chown -R "$USER":www-data /var/www
find /var/www -type f -exec chmod 0640 {} \;
sudo find /var/www -type d -exec chmod 2750 {} \;
Can then confirm permissions with
ls -la
Localhost
Kill a process running on localhost
First, find the process using
lsof -i :3000
Then, kill the process via the PID
kill <PID>
User management
Create a new user with sudo
Create the new user. Need to use sudo
if not signed in as root.
adduser <newuser>
Give sudo priveleges
usermod -aG sudo <newuser>
Useful terminal commands
cmp
- Compares to see if two files are equivalent
Create a RAID array
For a full article, reference How To Create RAID Arrays with mdadm on Ubuntu
Find existing RAID information
cat /proc/mdstat
If there is an existing array, it needs to be unmounted from the filesystem
sudo umount /dev/md0
Stop and remove the array
sudo mdadm --stop /dev/md0
Look at existing disk structure
lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT
Create the array (this example is for RAID 5)
sudo mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sda /dev/sdb /dev/sdc
Check the progress
cat /proc/mdstat
Create the filesystem on the array
sudo mkfs.ext4 -F /dev/md0
Create the mountpoint
sudo mkdir -p /mnt/md0
Mount
sudo mount /dev/md0 /mnt/md0
Check that the expected space is available
df -h -x devtmpfs -x tmpfs
Save the array layout
Warning
open: True The array needs to be completed before running the rest of the instructions
Make the array reassemble on boot (adjust the /etc/mdadm/mdadm.conf
)
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
sudo update-initramfs -u # Update initial RAM system
echo '/dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
Generate a random value (useful for secret keys)
openssl rand -hex 32