GNU/Linux general tips & tricks


Initial Rocky/Alma config

#!/bin/bash
echo "net.ipv6.conf.all.autoconf=0" >> /etc/sysctl.conf
echo 'export HISTFILESIZE= \
export HISTSIZE= \
export HISTTIMEFORMAT="[%F %T] " \' >> /etc/bachrc
source /etc/bachrc
dnf -y install qemu-guest-agent
dnf -y update && reboot

Initial Debian config

#!/bin/bash
echo "net.ipv6.conf.all.autoconf=0" >> /etc/sysctl.conf
sysctl --system
echo 'export HISTFILESIZE=' >> /etc/bashrc
echo 'export HISTSIZE=' >> /etc/bashrc
echo 'export HISTTIMEFORMAT="[%F %T] "' >> /etc/bashrc
echo 'alias ll="ls -lh"' >> /etc/bashrc
echo 'alias vi="vim.tiny"' >> /etc/bashrc
source /etc/bashrc
apt -y install qemu-guest-agent
apt -y update && apt -y upgrade
sleep 7
reboot

Create an LVM partition

fdisk /dev/sda
n (create new partition)
p (primary)
enter (partition number 1,2,3,4,5...)
enter (start block)
enter (end block)
t (modify type)
8e (LVM)
w (write changes to disk)

Autocomplete SSH on Debian

/etc/bash_completion.d/ssh
#!/bin/bash
_ssh()
 {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts=$(grep '^Host' ~/.ssh/config ~/.ssh/config.d/* 2>/dev/null | grep -v '[?*]' | cut -d ' ' -f 2-)

    COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
    return 0
}
complete -F _ssh ssh
chmod +x /etc/bash_completion.d/ssh
. /etc/bash_completion.d/ssh

Usefull GNU/Linux commands

1. Add/remove an IP address

To add/remove a single ipv4/ipv6 address from an interface, run:

ip addr <add/del> <youripaddress> dev <nameofinterface>

Examples:

ip addr add 192.128.0.1/24 dev ens32
ip addr del 2001:db8:f5:0:250:56ff:fe80:413f/64 dev ens32