Aide-Mémoire
Autre Cheatsheet
Gestion des devices
Bash |
---|
| # List of connected USB devices
lsusb
# Device messages
dmesg
|
KVM
Bash |
---|
| # List running VMs
virsh list
# List all VMs
virsh list --all
# Register a VM
virsh define <vm-domain-file>.domain.xml
# Remove from List
virsh undefine <vm-name>
# Start / Stop / Reboot a VMs
virsh start <vm-name>
virsh shutdown <vm-name>
virsh reboot <vm-name>
# Get VMs Details
virsh dominfo <vm-name>
# Connect to console
virsh console <vm-name>
|
Gestion des utilisateurs
Bash |
---|
| THEUSER=frodo
# Ajouter un utilisateur
adduser $THEUSER
# Ajouter l'utilisateur au group sudo
adduser $THEUSER sudo
# Voir la liste des users
cat /etc/passwd
|
Remove SUDO password, add at the end of /etc/sudoers: [username] ALL=(ALL) NOPASSWD: ALL
Edition de Fichier
Bash |
---|
| FILENAME=the_file.txt
#Print content of a file
cat $FILENAME
#See last 50 lines
tail -n50 $FILENAME
# Replace Strings examples
sed -i "s/127.0.0.1/$(cat ip.address)/g" overrides.json`
|
Process Command
Bash |
---|
| #List of running process
ps -aux | less
# Interactive list
top
# Look up or signal processes based on name and other attributes.
pgrep
# Display a tree of processes
pstree
# Detach a process (nohup, no hangup)
nohup ./process &
|
Network Command
Bash |
---|
| # Get a file from a http address
wget
# Execure GET (or POST... see help)
curl [URL]
# List All Open Ports
netstat -tulpn | grep LISTEN
# List DNS TXT entries
host -t txt o7conseils.com
# List All Active Port 22 in subnet
nmap -p22 192.168.25.0/24
# Log in remote shell
ssh user@192.168.99.101
# Get the list of interfaces
ip a
# Get ethernet card speed
cat /sys/class/net/<interface>/speed
|
nc example usage
get_system_info.sh |
---|
| # What kernel version is running
echo "---- System Information ----"
echo "Kernel name: $(uname -s)"
echo "Kernel release: $(uname -r)"
echo "Kernel version: $(uname -v)"
echo "Machine hardware name: $(uname -m)"
echo "Processor type: $(uname -p)"
echo "Hardware platform: $(uname -i)"
echo "Operating system: $(uname -o)"
echo ----
# Get the OS flavour
echo ""
if [ -f /etc/debian_version ]; then
echo OS Flavour: Debian
echo Debian version: $(cat /etc/debian_version)
elif [ -f /etc/system-release ]; then
echo OS Flavour: $(cat /etc/debian_version)
else
echo OS Flavour: Unknown
fi
echo ""
# See OS release
echo "---- Release Information ----"
cat /etc/os-release
echo "----"
|
Get Detailed hardware info: cat /proc/cpuinfo
See all Device (like GPU): lspci
Cron Job
Bash |
---|
| #See list of Jobs
crontab -l
#Set Jobs from a file
crontab filename
|
System Command
Bash |
---|
| #Start a service
systemctl start [name.service]
#Stop a service
systemctl stop [name.service]
#Re-Start a service
systemctl restart [name.service]
#View Service status
systemctl status [name.service]
#View Service status + more logs
systemctl status -n50 [name.service]
#See all available services
systemctl list-unit-files --type=service
#View Boot time of each service
systemd-analyze blame
systemctl reload [name.service]
#Reload all unit files
systemctl daemon-reload`
systemctl is-active [name.service]
|
Location of user services: /etc/systemd/system
Reference
Service parameters
Keys & Encryption
Bash |
---|
| # Creates a new SSH key
ssh-keygen -t rsa -b 4096 -C "<label, ex your e-mail>"
# Get the fingerprint of a certificate : MD5 or SHA256
ssh-keygen -E md5 -lf rsa.pub
ssh-keygen -E sha256 -lf phil-sp8.pub
# See Sha256 sum of a file (usually to validate a download)
sha256sum [filename]
# Get a user Public Key from Github
wget -O - https://github.com/myuser.keys
# Add to Authorized key for logins
wget -O - https://github.com/myuser.keys >> /home/myuser/.ssh/authorized_keys
|
Bash Script Util
Bash |
---|
| # See Return code of last command
echo $?
# Print yyyy-mm-dd
echo $(date '+%Y-%m-%d')
|
Condition (IF)
reference
Haut-Niveau : if [ $VERSION_ID == '2' ]; then [CMD] else [CMD2] fi
Bash |
---|
| grep $USER /etc/passwd
if [ $? -ne 0 ] ; then echo "not a local account" ; fi
|
Package Management
Remove un-used package : apt autoremove
Useful Package