Denis Machard

My technical gists

Infrastructure architect by profession but always consider himself as a developer and an open source enthusiast.
@github @mastodon @rss

Cheat sheets

Linux

Cheat sheetCommands
list timezone
timedatectl list-timezones
set new timezone
sudo timedatectl set-timezone Europe/Paris
update hostname
sudo hostnamectl set-hostname [new_name]
add static ip with Netplan
sudo vim /etc/netplan/01-cfg-ens19.yaml
network:
ethernets:
ens19:
addresses:
- 172.16.0.1/12
version: 2
sudo chmod 600 /etc/netplan/*
sudo netplan apply
lists network interfaces with NetworkManager
nmcli connection show
NAME UUID TYPE DEVICE
WiFi5 79361210-59bd-4a91-a4af-c78634446295 wifi wlp2s0
rename Interface with NetworkManager
nmcli connection modify “Wired connection 1” connection.interface-name “ens19”
add static IP with NetworkManager
nmcli con mod <NET_UUID> ipv4.address 192.168.1.2/24
nmcli con mod <NET_UUID> ipv4.gateway 192.168.1.1
nmcli con mod <NET_UUID> ipv4.method manual
nmcli con mod <NET_UUID> ipv4.dns 8.8.8.8
nmcli con mod <NET_UUID> autoconnect yes
nmcli con down <NET_UUID>
nmcli con up <NET_UUID>
display file permission and ownership
ls -alrt
-rwxrwxr–. 1 ansible automation 4 Nov 13 10:57 helloworld.txt

r = read = 4
w = write = 2
x = execute = 1
[ user = u ] [ group = g ] [ others = o ]
The user ansible has 4+2+1=7 (full access)
The group automation has 4+2+1=7 (full access)
All others have 4 (read-only)
change permission file or directory
chmod 644 myfile
change user and group appartenance
chown -R user:group /mydirectory/
list nvme disk
$ sudo fdisk -l /dev/nvme*
Extend physical drive partition
# check free space
sudo fdisk -l
# Extend physical drive partition
sudo growpart /dev/sda 3
# See phisical drive
sudo pvdisplay
# Instruct LVM that disk size has changed
sudo pvresize /dev/sda3
resize logical volume
# View starting LV
sudo lvdisplay
# Resize LV
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
df -h
#Resize Filesystem
sudo resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv
Create partition for New Disk
fdisk /dev/sdc
Command (m for help): n and enter
Command (m for help): w
format the disk with mkfs command
mkfs.ext4 /dev/xvdc1
share file with windows
sudo apt-get install samba
sudo smbpasswd -a denis
sudo vim /etc/samba/smb.conf
[data]
path = [folder_to_share]
valid users = [user]
read only = no
# guest ok = yes # no auth
sudo systemctl restart smbd
sudo systemctl enable smbd
add permanent dummy virtual interface
$ cd /etc/systemd/network/
$ sudo touch vbr0.netdev vbr0.network

$ sudo vim vbr0.netdev
[NetDev]
Name=vbr0
Kind=dummy

$ vim vbr0.network
[Match]
Name=vbr0
[Network]
Address=172.16.0.249
Mask=255.240.0.0
Broadcast=172.31.255.255

$ sudo systemctl restart systemd-networkd
$ sudo systemctl enable systemd-networkd

Ubuntu desktop

Cheat sheetCommands
show version ubuntu
lsb_release -a
install basic tools
sudo apt install vim net-tools htop vlc
sudo snap install jdownloader2
enable ssh server
sudo apt install openssh-server -y
Edit /etc/ssh/sshd_config
PasswordAuthentication yes
sudo systemctl restart ssh
create USB bootable
https://etcher.balena.io/#download-etcher

XRDP

Cheat sheetCommands
install XRDP
sudo apt-get install xrdp
sudo systemctl enable xrdp
sudo adduser xrdp ssl-cert
add setxkbmap fr to $HOME/.profile
quick fix for XRDP and Ubuntu 23.10
DesktopVer="$XDG_CURRENT_DESKTOP"
SessionVer="$GNOME_SHELL_SESSION_MODE"
ConfDir="$XDG_DATA_DIRS"
sudo sed -i “4 a #Improved Look n Feel Method\ncat «EOF > ~/.xsessionrc\n
export GNOME_SHELL_SESSION_MODE=$SessionVer\nexport XDG_CURRENT_DESKTOP=$DesktopVer\n
export XDG_DATA_DIRS=$ConfDir\nEOF\n” /etc/xrdp/startwm.sh
disable automatic login
sudo vim /etc/gdm3/custom.conf
AutomaticLoginEnable=false
disable systemd-resolved
sudo systemctl disable systemd-resolved.service
sudo systemctl stop systemd-resolved

$ sudo vim /etc/NetworkManager/NetworkManager.conf
dns=default

$ sudo rm /etc/resolv.conf
$ sudo systemctl restart NetworkManager.service
kill user session from command line
sudo pkill -9 -u denis

SSH

Cheat sheetCommands
generating a new SSH public and private key
ssh-keygen -b 4096
copy the public key to remote server
ssh-copy-id username@remote_host
disabling Root Login in SSHD
sudo nano /etc/ssh/sshd_config
PermitRootLogin no
sudo service sshd restart
disabling Password Authentication on SSHD
sudo nano /etc/ssh/sshd_config
PasswordAuthentication no
sudo service sshd restart

Git

Cheat sheetCommands
install git
sudo apt install git
config client
git config –global user.name <USER_NAME>
git config –global user.email <USER_EMAIL>
use your GPG key
git config –global commit.gpgsign true
git config –global user.signingkey <KEY_ID>

GPG

Cheat sheetCommands
list GPG keys
gpg –list-secret-keys –keyid-format=long
sec rsa4096/<KEY_ID> 2021-06-09 [SC]
generate a key
gpg –full-generate-key
update an existing key
gpg –edit-key <KEY_ID>
import key
gpg –import “gpg_private.key”
export GPG key
gpg –armor –export <KEY_ID>—–BEGIN PGP PUBLIC KEY BLOCK—–
mQINBGDBBhIBEADD/m4EK+XFiW20rE8fhLgom+zI/eExjaTUbLrLPj2q6SxxX2rg

mQINBGDBBhIBEADD/m4EK+XFiW20rE8fhLgom+zI/eExjaTUbLrLPj2q6SxxX2rg
—–END PGP PUBLIC KEY BLOCK—–

Vim

Cheat sheetCommands
Delete specific lines
:g/<REGEX_PATTERN>/d

Docker

Cheat sheetCommands
Install dockerhttps://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

PowerDNS / pdns-auth

Cheat sheetCommands
Install sqlite db
sudo apt install sqlite3
wget [github_url_pdns]/master/modules/gsqlite3backend/schema.sqlite3.sql
sqlite3 pdns.db
.read schema.sqlite3.sql
.quit
list all zones
sudo docker compose exec pdns pdnsutil list-all-zones
Create zone
sudo docker compose exec pdns pdnsutil create-zone home.
add records
pdnsutil add-record home. ns1 A 3600 172.16.0.253
New rrset:
ns1.home. 3600 IN A 172.16.0.253
Update record
pdnsutil replace-rrset home. test A 3600 192.168.1.253
Current records for test.home IN A will be replaced
New rrset:
test.home. 3600 IN A 192.168.1.253
propulsed by hugo and hugo-theme-gists