Linux & Bash Command Centerday-to-day reference · interactive
/

Everything you need at the terminal, in one place

Searchable, copy-pasteable commands for daily Linux/Bash work — filesystem basics through SSH, systemctl, WSL2 and networking. Type in the search bar or jump via the sidebar. Click any code block to copy it.

0commands indexed
0categories
0favorited
🟢 beginner 🔵 intermediate 🟠 advanced 🔴 use with care ✕ clear filters
🔐

Permissions & Ownership

chmod, chown, sudo

midLock down SSH key perms

SSH refuses to use keys with overly-open permissions — this is the fix for "Permission Denied (publickey)".

chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys

easyMake a script executable

Add the execute bit so you can run it with ./script.sh.

chmod +x script.sh

midchown

Change the owning user and group of a file.

chown user:group file.txt

midOctal permission cheat

read=4, write=2, execute=1 — sum per owner/group/other. 755 = rwxr-xr-x.

chmod 755 file.sh # rwxr-xr-x
📦

Package Management (apt)

Debian / Ubuntu

easyUpdate & upgrade

Refresh the package index, then upgrade installed packages.

sudo apt update sudo apt upgrade

easyInstall / remove

Install or uninstall a package by name.

sudo apt install <package> sudo apt remove <package>

midPi-hole update

Update Pi-hole itself, or force a manual ad-list refresh.

sudo pihole -up sudo pihole -g
🔎

Text Processing & Search

grep, sed, awk and friends

midgrep

Search for text in a file, or recursively through a directory.

grep 'pattern' file.txt grep -r 'pattern' .

advsed

Stream-edit a file: find and replace text.

sed 's/old/new/g' file.txt

advawk

Extract a column of data from structured text output.

awk '{print $1}' file.txt

midsort / uniq / wc

Sort lines, drop adjacent duplicates, and count lines.

sort file.txt uniq file.txt wc -l file.txt

advWhat's listening?

See which processes are bound to which ports. ss is the modern, always-installed alternative.

sudo lsof -i -P -n | grep LISTEN sudo ss -tulpn
🧩

Bash Scripting

Variables, conditionals, loops, redirection

easyFirst script

The shebang line tells the OS which interpreter to run.

#!/bin/bash echo "Hello, $USER"

advStrict mode

Abort on error, on unset variables, and on a failure anywhere in a pipeline. Put it under the shebang of every real script.

#!/bin/bash set -euo pipefail

Note: without it, a failing command mid-script keeps going and can do real damage.

easyVariables

No spaces around =. Use braces to disambiguate.

name="Vinay" echo "Hello, ${name}!"

midif / elif / else

Branch on an argument or condition.

if [ "$1" == "start" ]; then echo "Starting..." elif [ "$1" == "stop" ]; then echo "Stopping..." else echo "Unknown" fi

midLoops

for iterates a list; while runs until its condition is false.

for i in 1 2 3; do echo "Number: $i" done

midRedirection & pipes

Send output to files or chain commands together.

command > file.txt command >> file.txt command 2> errors.log command1 | command2

advAuto-reconnect loop

A resilient SSH session that reconnects on drop — from real usage notes.

#!/bin/bash while true; do ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=120 miniPC-Ubuntu echo "Disconnected. Reconnecting in 5s..." sleep 5 done

midRun detached

Keep a process alive after you close the terminal.

nohup ./script.sh &

advCron scheduling

Run a script automatically on a schedule.

crontab -e # min hour day month weekday command 0 6 * * * /home/user/backup.sh
⚙️

Processes & systemctl

Managing services like SSH

midView & kill processes

List running processes and stop one by PID.

ps aux top kill <PID> kill -9 <PID>

midsystemctl basics

Start, stop, restart, or check status of any service (e.g. ssh).

sudo systemctl status ssh sudo systemctl start ssh sudo systemctl restart ssh

advEnable on boot

Crucial: makes a service start automatically every boot.

sudo systemctl enable ssh sudo systemctl disable ssh

midmacOS equivalent

launchctl is macOS's version of systemctl for checking services.

sudo launchctl list | grep ssh
🌐

Networking

Static IPs, connectivity, Tailscale

easyCheck connectivity

Show interfaces/IPs, routing table, and test a connection.

ip a ip route ping google.com

advFind connection name

Step 1 before setting a static IP with nmcli.

nmcli connection show

advSet a static IP

Configure a fixed IP, gateway, and DNS via NetworkManager.

sudo nmcli connection modify preconfigured \ ipv4.method manual \ ipv4.addresses 192.168.50.XXX/24 \ ipv4.gateway 192.168.50.1 \ ipv4.dns "192.168.50.2 192.168.50.1"

Then: sudo nmcli connection down/up preconfigured or sudo reboot

midChange hostname

Rename the machine on the network.

sudo hostnamectl set-hostname your-new-name

midTailscale status

Check your mesh VPN connection and MagicDNS IP.

tailscale status tailscale ip -4

advTailscale fixes

Force reauth, or fix a Pi reporting "Internet Down".

tailscale up --force-reauth sudo tailscale up --accept-dns=false
🔑

SSH

Keys, config, and troubleshooting

midGenerate a key

-N "" skips the passphrase for a passwordless key.

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -C "my key" -N ""

midCopy key to remote

Enable passwordless login to a Linux/WSL machine.

ssh-copy-id -i ~/.ssh/id_ed25519 user@remote-ip -p 2222

adv~/.ssh/config

Turn `ssh user@ip -p 2222` into just `ssh myhost`.

Host miniubuntu HostName 100.113.205.109 User vinay8671 Port 2222 IdentityFile ~/.ssh/id_ed25519 ServerAliveInterval 60 ServerAliveCountMax 120 TCPKeepAlive yes

midCopy files over SSH

scp for one-off copies; rsync resumes and only sends what changed. Note scp uses -P for port, rsync passes it through -e.

scp -P 2222 file.txt user@host:~/ rsync -avz -e 'ssh -p 2222' dir/ user@host:~/dir/

Careful: a trailing slash on the rsync source copies the contents, not the folder itself.

midFix "host identification changed"

Clear a stale fingerprint after a server was rebuilt.

ssh-keygen -R [IP_ADDRESS] ssh-keygen -R [HOSTNAME]

advFix "Permission Denied"

Almost always a permissions problem on the key files.

chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys

advWindows SSH (PowerShell)

Check/start the service and open a firewall port.

Get-Service sshd Start-Service sshd Set-Service sshd -StartupType Automatic New-NetFirewallRule -Name "SSH2200" -DisplayName "SSH Port 2200" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 2200
🪟

WSL2

Windows Subsystem for Linux config

advStable .wslconfig

Place at C:\Users\<you>\.wslconfig — keeps SSH reachable and WSL awake.

[wsl2] localhostForwarding=true networkingMode=nat incomingTcpPorts=2222 autoMemoryReclaim=disabled vmIdleTimeout=0

Apply with wsl --shutdown, then restart WSL.

midEnable SSH in WSL

Fixes ssh.service showing "inactive (dead)".

sudo systemctl enable ssh sudo systemctl start ssh

advAuto-mount Windows folders

Edit /etc/wsl.conf so C:\ and D:\ mount cleanly with correct permissions.

[automount] enabled = true root = /mnt/ options = "metadata,umask=22,fmask=11" mountFsTab = false

midSymlink a Windows folder

Bring a Windows folder into your Linux home directory.

ln -s /mnt/c/Users/Vinay/Projects ~/WindowsProjects
📋

Quick-Reference Tables

Cross-platform SSH & systemctl at a glance

GoalLinux / MacWindows (PowerShell)
Check SSH servicesystemctl status sshGet-Service sshd
Start SSH servicesudo systemctl start sshStart-Service sshd
Restart SSH servicesudo systemctl restart sshRestart-Service sshd
Enable SSH on bootsudo systemctl enable sshSet-Service sshd -StartupType Automatic
Generate SSH keyssh-keygen -t ed25519ssh-keygen -t ed25519
Copy key to remotessh-copy-id user@hostmanual Add-Content to authorized_keys
Open firewall portsudo ufw allow 2200/tcpNew-NetFirewallRule ...
TaskCommandDescription
Start the servicesudo systemctl start sshdStarts the SSH daemon, allowing connections immediately.
Stop the servicesudo systemctl stop sshdImmediately shuts down the SSH daemon, disconnecting all users.
Restart the servicesudo systemctl restart sshdStops then starts. Use after editing /etc/ssh/sshd_config.
Check statussudo systemctl status sshdShows running/failed state, PID, and last log lines.
Enable on bootsudo systemctl enable sshdCrucial — service auto-starts every boot.
Disable on bootsudo systemctl disable sshdPrevents auto-start on boot.
💻

Terminal Playground

A tiny fake shell to practice a handful of commands (runs entirely in your browser)

vinay@sandbox: ~
$
¯\_(ツ)_/¯
No commands match ""