Linux Commands
Misc. Linux commands.
Account
Last Modify
1
| chage -d YYYY-MM-DD <user>
|
Password Never Expire
1
| chage -I -1 -m 0 -M 99999 -E -1 <user>
|
Lock/Unlock
1
2
3
4
5
| passwd -l <user> # Lock
passwd -u <user> # Unlock
usermod -L <user> # Lock
usermod -U <user> # Unlock
|
Reset Fail Login
1
| pam_tally2 -r -u <user>
|
Sudo NOPASSWD
In /etc/sudoers
, add NOPASSWD
to sudo group.
1
| %sudo ALL=(ALL:ALL) NOPASSWD:ALL
|
SSH
Remove Known Hosts
1
2
| ssh-keygen -R <hostname/ip>
ssh-keygen -f "~/.ssh/known_hosts" -R <hostname/ip>
|
ProxyCommand
host test
ProxyCommand ssh -W %h:%p jumpserver
ProxyJump
host test
ProxyJump jumpserver
Rotate Frame Buffer
Number can be 1
, 2
, 3
1
2
| echo 1 > /sys/class/graphics/fbcon/rotate_all
echo 1 > /sys/class/graphics/fbcon/rotate
|
File System
Resize Filesystem
Usually use after a partition / image resize
1
2
| resize2fs <device>
resize2fs /dev/sda1
|
Disable journal on ext4
1
| tune2fs -O ^has_journal /dev/<disk>
|
Create Sparse File
truncate -s <size> <filename>
1
2
3
4
5
6
7
| $ truncate -s 10G 10G.txt
$ ls -lah 10G.txt
-rw-r--r-- 1 user user 10.0G Apr 1 00:00 10G.txt
$ du -sh 10G.txt
0 10G.txt
|
Ref: Sparse file wikipedia
File
Find
Find x-days before and action
In actuality, it should be (x-1).
1
| /bin/find <path> -maxdepth 1 -mtime +<x> -type f -name "<pattern>" -exec rm -f {} \;
|
Find x-minutes before and action
1
| /bin/find <path> -maxdepth 1 -mmin +<x> -type f -name "<pattern>" -exec rm -f {} \;
|
Detect Text File Charset/Encoding
Convert Text File Charset/Encoding
1
2
| iconv iconv -f <file charset> -t <output charset> <file.txt>
iconv iconv -f jis -t utf8 readme.txt
|
Content Type
Image Info
1
| magick identify <filename>
|
Timeout
1
2
3
| timeout <duration> <command ...... >
timeout 1d tcpdump -n -i eth0 port 22 -s 65535 -w ssh_dump.cap &
nohup timeout 1d tcpdump -n -i eth0 port 22 -s 65535 -w ssh_dump.cap &
|
Rsync
1
| rsync -vahpt --size-only --stats --del <source> <target>
|
<source>
is put/sync INTO <target>
directory, not replacing <target>
.
Network
Avahi/MDNS
Show All Entries
1
2
| avahi-browse -a
avahi-browse -a -d <domain> # specify domain other than .local
|
Lookup
1
2
| avahi-resolve -n4 door.local
avahi-resolve -n6 door.local
|
Ban IP
IPTables
1
2
| iptables -A INPUT -s <IP> -j DROP
ip6tables -A INPUT -s <IP> -j DROP
|
Fail2ban
1
2
| fail2ban-client status # show jail list
fail2ban-client -vvv set <jail from list> banip <ip>
|
Check NIC status
Check WiFi SSID
1
2
| iw dev <wifi nic> scan
iw dev wlan0 scan
|
Enable BBR
Create file /etc/sysctl.d/10-network-bbr.conf
with following content and reboot:
1
2
| net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
|
Test Connection UDP
1
2
| nc -z -v -u [hostname/IP address] [port number]
nc -z -v -u 8.8.8.8 53
|
Curl
Skip certificate checking
1
| curl -k ... # Use -k to skip certificate check.
|
DNS Over HTTPS
1
2
| curl -sH 'accept: application/dns-json' 'https://dns.google/resolve?name=google.com' | jq .
curl -sH 'accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=google.com' | jq .
|
Journalctl
List Field
List Identifier
Identifier value can be used in -t
.
1
| journalctl -F SYSLOG_IDENTIFIE
|
John Siu
Update: 2023-09-28
comments powered by