Migration

You inherited a Linux server. Here is how to find out what is on it

In this article11 sections

A previous developer left. An agency handed over a login and a one-line note. A colleague moved on and the server stayed behind. Now it runs something the business depends on, and nobody can say what.

This is more common than most people admit, and the temptation is to start fixing things straight away. Do not. The first job is a read-only audit: find out what is there before you change anything. Changes made without knowing what depends on what are how working servers become broken ones.

This guide gives you the questions, the commands and the order. Nothing in the audit section modifies the system.

The ground rules

  • Read first, change later. Everything in the audit below only reads. The one exception is apt update, which refreshes the list of available packages and installs nothing.
  • Work as a normal user with sudo, not by logging in as root, so that your commands are recorded.
  • Keep notes as you go, in a text file with the command and what it showed. You are building the document that did not exist.
  • Take a snapshot at the provider before you start, and a second copy of anything that matters before you change it.
  • Do not trust names. A folder called old may be live; a service called test may take real orders.

1. What is this machine?

hostnamectl
cat /etc/os-release
uptime
lscpu | grep -E 'Model name|^CPU\(s\)'
free -h
df -h
df -i

Note the operating system and version, because it decides how long it will receive security updates. Ubuntu LTS releases are supported for five years from release; older ones are not. Check disk use and, separately, inode use (df -i): a server can have free space and still refuse to create files.

2. What is running and listening?

sudo ss -tulpn
systemctl list-units --type=service --state=running
systemctl list-timers --all
ps aux --sort=-%mem | head -15

ss -tulpn is the most useful single command: it lists every port that accepts connections and the program that owns it. Read it twice. For each line, answer: should the internet be able to reach this?

  • Ports 22, 80 and 443 on the public address are normal.
  • A database port (3306 MySQL or MariaDB, 5432 PostgreSQL, 6379 Redis, 27017 MongoDB) bound to 0.0.0.0 or to a public address is a serious finding. It should be bound to 127.0.0.1 or a private address.
  • Anything you cannot name is a question for the next section.

If Docker is installed, list the containers and what they publish:

sudo docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Ports}}'

Published container ports can bypass a host firewall. Note any that listen on all addresses.

3. What websites and apps does it serve?

For NGINX:

sudo nginx -T 2>/dev/null | grep -E 'server_name|root |proxy_pass|fastcgi_pass|listen '
ls -l /etc/nginx/sites-enabled/

For Apache:

sudo apache2ctl -S
ls -l /etc/apache2/sites-enabled/

Then look at what is on disk:

ls -la /var/www/ /srv/ /opt/ /home/

Make a table: domain, document root, language and framework, database, owner. Each row is a site you now look after. Check that DNS agrees with the server:

dig +short example.com
curl -s ifconfig.me

If a domain points here but has no site configured, or a site is configured for a domain that points elsewhere, write it down.

4. Who can get in?

This is the section people skip, and it is the one that matters most after a handover.

getent passwd | awk -F: '$3 >= 1000 && $3 < 65000 {print $1, $6, $7}'
sudo grep -v '^#' /etc/sudoers /etc/sudoers.d/* | grep -v '^$'
getent group sudo
sudo last -n 30
sudo lastb -n 20 2>/dev/null

Then the SSH keys, for every account that has a home folder:

sudo sh -c 'for f in /root/.ssh/authorized_keys /home/*/.ssh/authorized_keys; do [ -f "$f" ] && echo "== $f" && cut -c1-80 "$f"; done'

Each line is a person or a machine that can log in without a password. Ask who owns each one. Keys with comments like jenkins, backup or a person’s name give clues; keys with no comment are questions. And check how SSH is configured:

sudo sshd -T | grep -E '^(permitrootlogin|passwordauthentication|port|allowusers) '

5. What runs on a schedule?

Scheduled jobs are the hidden half of a server: backups, renewals, imports, clean-ups, and sometimes things nobody remembers.

sudo ls -la /etc/cron.d /etc/cron.daily /etc/cron.hourly /etc/cron.weekly
for u in $(cut -d: -f1 /etc/passwd); do sudo crontab -l -u "$u" 2>/dev/null | sed "s/^/$u: /"; done | grep -v ': #'
systemctl list-timers --all

Open each script that appears. Look for: what it does, where it writes, whether it sends output somewhere, and whether it contains passwords.

6. Where is the data, and is it backed up?

sudo du -h --max-depth=1 /var/www /var/lib 2>/dev/null | sort -h | tail -15
sudo mysql -e "SELECT table_schema, ROUND(SUM(data_length + index_length)/1024/1024) AS size_mb FROM information_schema.tables GROUP BY table_schema ORDER BY size_mb DESC;"
sudo find / -xdev \( -name '*.sql' -o -name '*.sql.gz' -o -name '*.tar.gz' -o -name '*.bak' \) -size +1M -mtime -60 2>/dev/null | head -20

Then the question that decides how worried you should be: is there a backup, and has anyone ever restored it? Look for the backup job in the cron output above, find where it writes, and check whether those files are recent and whether they are stored on the same machine (which protects against nothing if the machine dies). A backup that has never been restored is a hope.

7. What is out of date or exposed?

sudo apt update
apt list --upgradable 2>/dev/null | head -30
ls /var/run/reboot-required 2>/dev/null && cat /var/run/reboot-required.pkgs
sudo ufw status verbose
sudo certbot certificates 2>/dev/null

For WordPress sites, check core, plugins and themes (with WP-CLI, if installed):

cd /var/www/example.com && sudo -u www-data wp core version && sudo -u www-data wp plugin list --update=available

Also look for files that should never be in a web root:

sudo find /var/www -maxdepth 3 \( -name '.env' -o -name '.git' -o -name 'phpinfo.php' -o -name '*.sql' -o -name 'wp-config.php.bak' \) 2>/dev/null

Write down each result, but do not delete anything yet. A .git folder in a web root may be a leak, and it may also be the only copy of the source.

8. Write the inventory

At the end you should be able to fill in one page:

  • What it is: provider, operating system, size, public address.
  • What runs: each site and service, with its owner and its database.
  • Who has access: accounts, keys, panels, and which of them you can explain.
  • What is scheduled: each job, and what depends on it.
  • Where the data is: and the state of the backups.
  • Risks, ranked: exposed database ports, no backups, end-of-life operating system, unexplained keys, unpatched software.

Then: rotate before you rebuild

Once you understand the machine, the first changes are cheap and safe, and they reduce the largest risk: access you do not control.

  1. Take a verified backup and a snapshot.
  2. Remove keys and accounts that nobody can explain, one at a time, testing logins between changes.
  3. Rotate secrets: database passwords, application keys, API tokens and the keys inside .env files. People who worked on the server may still hold them.
  4. Close what should not be public: bind databases to localhost, enable the firewall (allowing SSH first).
  5. Patch the operating system and the application stack on a schedule you choose, not in a panic.
  6. Only then plan larger changes, such as a migration to a newer server.

When it is worth getting help

A read-only audit takes a careful person a few hours and produces the one document that makes every later decision cheaper. If you would rather not do it yourself, or if the server is one the business cannot afford to get wrong, I do this work: read-only first, a written inventory with ranked risks, and only then a proposal for what to change.

You can see my profile on Upwork and send me a short description of the server, or read about server migration and server hardening. For a quick first look, try the free server health check.