↓Skip to main content

Linux Daily Commands

795 words·
Linux Bash Commands
Table of Contents

Remove Host Key
#

# Remove host keys from ~/.ssh/known_hosts file
ssh-keygen -R 10.0.150.100

Set Temporary DNS server
#

# Set temporary DNS server (till reboot)
sudo sh -c 'printf "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" > /etc/resolv.conf'

Test TLS Certificate
#

# List certificate details
timeout 5 openssl s_client -connect example.com.work:443 -servername example.com.work </dev/null 2>/dev/null | openssl x509 -noout -text
# List certificate details, short version
curl -vI https:/blog.jklug.work 2>&1 | grep -A5 "Server certificate"

# Shell output:
* Server certificate:
*   subject: CN=*.jklug.work
*   start date: Oct 25 00:00:00 2026 GMT
*   expire date: May 10 23:59:59 2027 GMT
*   issuer: C=US; O=Amazon; CN=Amazon RSA 2048 M04
*   Certificate level 0: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption

Encode Private SSH Key
#

# Encode Private SSH Key
openssl base64 -in deploy_key -A && printf '\n'

List Public IP
#

# List public IP
curl -s https://ifconfig.me

List Reboots
#

# List reboots in alst 3 days
last reboot --since "3 days ago"

# Shell output:
reboot   system boot  6.12.15-current- Mon Dec 22 15:24   still running
reboot   system boot  6.12.15-current- Mon Dec 22 04:16 - 15:23  (11:07)
reboot   system boot  6.12.15-current- Sun Dec 21 04:11 - 04:16 (1+00:05)
reboot   system boot  6.12.15-current- Sat Dec 20 04:05 - 04:11 (1+00:06)

Harbor Login & Push
#

# Login to Harbor
docker login harbor.jklug.work -u 'username' -p 'password'
# Tag the image for Harbor
docker tag nginx harbor.jklug.work/example-project/dev/example-image:0.0.1

# Push the image to Harbor
docker push harbor.jklug.work/example-project/dev/example-image:0.0.1

Linux System Storage Cleanup
#

ncdu Package / List Storage Usage
#

# Install on Ubuntu / Debian
sudo apt install ncdu

# Install on Fedora
sudo dnf install ncdu
# Open ncdu for root
sudo ncdu /

# Shell output:
  123.7 GiB [####################] home                                                                                                                                                                                                
   39.1 GiB [###########         ] /opt
   29.1 GiB [########            ] /var
   12.9 GiB [###                 ] /usr
  625.4 MiB [                    ] /boot
   48.9 MiB [                    ] /tmp
   36.3 MiB [                    ] /etc
.   2.6 MiB [                    ] /run
   96.0 KiB [                    ] /dev
   52.0 KiB [                    ] /root
    4.0 KiB [                    ]  .profile
@   4.0 KiB [                    ]  lib64
@   4.0 KiB [                    ]  sbin
@   4.0 KiB [                    ]  lib
@   4.0 KiB [                    ]  bin
.   0.0   B [                    ] /proc
    0.0   B [                    ] /sys
e   0.0   B [                    ] /srv
e   0.0   B [                    ] /mnt
e   0.0   B [                    ] /media
e   0.0   B [                    ] /afs

Docker
#

# List Docker storage usage
docker system df

# Output:
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          35        1         25.4GB    25.13GB (98%)
Containers      1         1         0B        0B
Local Volumes   1         1         0B        0B
Build Cache     144       0         11.77GB   11.77GB
# Docker cleanup
sudo docker system prune

# Shell output:
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - unused build cache

Apt Cache
#

# Clean apt cache
sudo apt clean

Journald
#

# List journald storage usage
journalctl --disk-usage

# Shell output:
Archived and active journals take up 1.8G in the file system.
# Clean journald storage
sudo journalctl --vacuum-size=500M



Docker Hub Registry Rate Limit
#

# Output the Docker Hub Registry rate limit
TOKEN=$(curl -s \
  "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" \
  | jq -r .token)

curl -sI -H "Authorization: Bearer $TOKEN" \
  https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest \
  | grep -i ratelimit

# Shell output: (Refreshes in 6 hours)
docker-ratelimit-source: <public-ip>
x-ratelimit-limit: 100;w=3600
ratelimit-limit: 100;w=3600
x-ratelimit-remaining: 100;w=3600
ratelimit-remaining: 100;w=3600

Remove Partition
#

Local
#

# List storage devices
lsblk

# Shell output:
NAME               MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
nvme0n1            259:0    0   1.8T  0 disk 
├─nvme0n1p1        259:1    0    16M  0 part 
└─nvme0n1p2        259:2    0   1.8T  0 part 
# Remove partitions from disk
dd if=/dev/zero of=/dev/nvme0n1 bs=1M count=100 status=progress conv=fsync

# Recognize the disk changes immediatel
partprobe /dev/nvme0n1

# Reread the partition table of that drive
udevadm settle

USB Mounted SSD
#

# List storage devices
lsblk -o NAME,SIZE,MODEL,SERIAL,TRAN,MOUNTPOINTS /dev/sda

# Shell output:
NAME     SIZE MODEL                   SERIAL          TRAN MOUNTPOINTS
sda    931.5G Samsung SSD 980 PRO 1TB S5GXNX1W313924A usb  
├─sda1    16M                                              
└─sda2 931.5G                                              /run/media/fedora/980pro-1tb_vm-backup-old
# Unmount
sudo umount /dev/sda2
# Wipe partition
sudo wipefs --all /dev/sda1 /dev/sda2

# Shell output:
/dev/sda2: 8 bytes were erased at offset 0x00000003 (ntfs): 4e 54 46 53 20 20 20 20
# Wipe partition
sudo wipefs --all /dev/sda

# Shell output:
/dev/sda: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 8 bytes were erased at offset 0xe8e0db5e00 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sda: calling ioctl to re-read partition table: Success
# Verify cleanup
lsblk -f /dev/sda

# Shell output:
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sda                                         
# Remove USB device
sync
udisksctl power-off -b /dev/sda