How to greet an unknown Linux system
Sometimes you find yourself (with an SSH connection or otherwise) in the shell of a system you know nothing about beyond its hostname – what to do?
There are many ways to go about this, but here is my quick cheatsheet to get you started. Excuse the terrible analogies.
Hi, how are you?
Start politely by checking how long the system has been up, load, what users are logged in and what they are doing:
w
The command w
combines several other Unix programs: who
, uptime
and ps -a
.
Who are you? (determine OS version and hostname)
Type any one of the following commands to find OS name, version and hostname:
cat /etc/os-release
lsb_release -a
hostnamectl
Some more for Unix systems (including MacOS):
uname -a
hostname
sw_vers
What are you packing? (inspect hardware)
If you want to know some basics about the system hardware, try these:
lscpu
lshw –List Hardware
hwinfo
cat /proc/cpuinfo
cat /proc/version
It’s also nice to get an overview of the filesystem disk space usage:
df -h
So, what do you do? (list running services)
You first need to determine the system manager:
pstree | head -n 5
The very first process in the tree should be the system manager. It’s most likely systemd
, upstart
or init
(SysVinit).
List services
SystemD:
sudo systemctl list-units --type=service --all
Upstart:
sudo initctl list
SysVinit:
sudo service --status-all
But what do you really do? (list running processes)
Get a real-time overview of running processes:
top
List all running processes:
ps ax
Anyway, what’s in your bag? (list installed software)
You first need to determine the package manager. This depends on the Linux distribution.
Try checking for a few popular ones:
which apt-get
which pacman
which nix-env
If none of these are installed – look up what package manager the linux distribution typically comes with.
apt-get/dpkg (Debian, Ubuntu)
List manually installed packages:
apt-mark showmanual
List all installed packages:
dpkg --get-selections | grep -v deinstall
Get the full install history:
zgrep -hE '^(Start-Date:|Commandline:)' $(ls -tr /var/log/apt/history.log*.gz ) \
| egrep -v 'aptdaemon' \
| egrep -B1 '^Commandline:'
pacman (Arch)
List manually installed packages:
pacman -Qe
List all installed packages:
pacman -Q
Get the full install history:
/var/log/pacman.log
OK, what now?
By now you should hopefully have all the clues you need to look up how to do whatever you were planning to do on the (previously unknown) linux system.
Good luck. Be nice.