How to clone a Linux server – install same packages onto another server

This small guide is meant for those who need to

  • clone an existing server/desktop the hard way (for those who lack virtualization tools)
  • start from scratch with all packages previously installed (with or without maintaining the personalized settings)


  1. Get the current installed packages on the main machine: dpkg –get_selections > installed_packages.txt
  2. Make a copy of your old /etc/apt/sources.list and copy everyting from /etc/apt/sources.list.d/* onto your new machine
  3. Still on the new new machine, make sure you install dselect: apt-get install dselect
  4. Update to check for missing keys: apt-get update
  5. And add the missing keys: apt-key adv –keyserver –recv-keys XXXXXXXX
  6. Update again: apt-get update
  7. Register the new packages: dpkg –set-selections < installed_packages.txt


Now the fun part – use dselect to install the missing packages:

  • dselect update
  • dselect install

If you’d like the same personalized settings, simply copy the config files and folders from your /home/user located on the old machine -> onto the new machine. Same rule applies for other programs (apache, fpm, postfix): copy all files from /etc/apache, /etc/postfix and so on onto the new machine. For the future, using rsync or something similar might come more in handy.

This was the ‘hard way’ of cloning a server. Since the best sysadmin is a lazy sysadmin, you might want to consider Chef/Puppet/Ansible/SaltStack or any virtualization & cloning tool.



Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s