Skip to content

Linux Notes#

The Filesystem Hierarchy Standard (FHS)#

  • /bin/: basic programs.
  • /boot/: Kali Linux kernel and other files required for its early boot process.
  • /dev/: device files.
  • /etc/: configuration files.
  • /home/: user's personal files.
  • /lib/: basic libraries.
  • /media/: mount points for removable devices (CD/DVD-ROM, USB keys, and so on).
  • /mnt/: temporary mount point.
  • /opt/: extra applications provided by third parties.
  • /root/: administrator's (root's) personal files.
  • /run/: volatile runtime data that does not persist across reboots (not yet included in the FHS).
  • /sbin/: system programs.
  • /srv/: data used by servers hosted on this system.
  • /tmp/: temporary files (this directory is often emptied at boot).
  • /usr/: applications (this directory is further subdivided into bin, sbin, lib according to the same logic as in the root directory) Furthermore, /usr/share/ contains architecture-independent data. The /usr/local/ directory is meant to be used by the administrator for installing applications manually without overwriting files handled by the packaging system (dpkg).
  • /var/: variable data handled by services. This includes log files, queues, spools, and caches.
  • /proc/ and /sys/ are specific to the Linux kernel (and not part of the FHS). They are used by the kernel for exporting data to user space.

Environmental variables#

  • System-wide: /etc/profile/.
  • Per user: ~/.profile.

Services configuration#

SSH#

  • For safety reasons after installation generate new SSH host keys:
sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server
  • generate new SSH host keys:
ssh-keygen
  • Copy public key to server:
ssh-copy-id user@host
  • Update /etc/ssh/ssh_config file:
Host *
    StrictModes yes
    ForwardX11 no
    ClientAliveInterval 360
    ClientEmptyPasswords no
    AllowUsers kali
    Protocol 2
    PasswordAuthentication no
  • Create ~/.ssh/config file if necessary:
Host hostname1
    SSH_OPTION value
    SSH_OPTION value

Host hostname2
    SSH_OPTION value

Host *
    SSH_OPTION value
  • update .ssh folder and config file rights:
chmod 0700 ~/.ssh
chmod 600 ~/.ssh/config

IP Tables#

iptables essentials

Commands usage and examples#

rsync#

rsync [OPTION...] SRC... [DST...]

Flags#

  • a: archive mode, or faster way to specify recursion and necessity of preserving everything.
  • z: compress file data during transfer.
  • h: human readable.
  • v: verbose.

Examples#

  • find by date and sync:
sudo find SRC -type f -newermt DATE_BEGIN ! -newermt DATE_END > files_to_sync.txt

sudo rsync -avP `cat files_to_sync.txt` DST

sudo rsync -avP USER@HOST:SRC DST

VA#

How to check disk space#

To check files and directories usage use the du command. To get info about how much disk space your filesystem is using run df command. Use -h flag to get human readable answer. These commands can be run for particular file or folder or the whole filesystem.

How to change host name#

To change machine name on Linux just edit the /etc/hostname and /etc/hosts files and reboot the system.

How to unmask systemd service#

Based on unix.stackexchange answer:

  • Check that a file is a symlink to /dev/null:
file /etc/systemd/system/my_app.service
file /lib/systemd/system/my_app.service
  • Delete the symlink:
sudo rm /etc/systemd/system/your_app.service
  • Reload systemd daemon as you changed a service:
sudo systemctl daemon-reload
  • Check service status:
systemctl status my_app

Make file executable#

To make file executable use this command:

chmod u+x <file>

Add opacity to Lxterminal#

sudo apt-get install compton
  • Use xprop command to get necessary app window properties.
  • Search for WM_CLASS(STRING) = APP_NAME property.
  • Use found name in class_g argument.
  • Add opacity settings for ~/.config/compton.conf:
sudo 'opacity-rule = ["75:class_g *= 'APP_NAME'"]' > ~/.config/compton.conf
  • Add compton to ~/.config/lxsession/Lubuntu/autostart
sudo 'compton' > ~/.config/lxsession/Lubuntu/autostart

Get all user names#

To get all user names from /etc/passwd use the following command:

cut -d: -f1 /etc/passwd

Get current shell#

To know which shell you are currently running use the following command:

ps -p $$

How to activate shared folder in VMWare#

To activate VMWare shared folder (source article on medium):

  • add shared foleder in settings;
  • check that folder is in place:

vmware-hgfsclient

  • create directory inside /mnt/hgfs/:

mkdir /mnt/hgfs/shared

  • share created dorectory:

sudo vmhgfs-fuse .host:/shared-folder-name /mnt/hgfs/shared -o allow_other -o uid=1000

Note

vmtools drivers should be installed to succesfully fulfil the operation.