Ubuntu – Ubuntu server installation with root only

rootserversystem-installation

I'm trying to replicate locally the kind of image VPS providers (DigitalOcean, Vultur, etc) gives me when I deploy on their services. To my knowledge, their base images are pretty vanilla, so I though the official ubuntu server images would be just perfect to boot in Virtual Box and I'd be done with it. Problem is: the official image forces me to create a sudo user.

This is great in a normal usage, but when I spin an instance on a VPS, I'm starting only with root as user. Is there any way to make an installation without sudo user with the official ISO image? (I'm open to a Vagrant Box is there is one too!)

Please note:

  • I know running on root user is bad, I'm only doing it locally, "for science";
  • I know I can sudo su from my user, but this is not what I want;

Again, I want to have it like they give it to me with the VPS providers… But thanks for your concerns on security 😉

Best Answer

This is a step-by-step example of how to do it by enabling root and deleting the user, as mentioned by user Byte Commander

  • ssh into the installation as the user USERNAME created during installation
  • sudo su to become root
  • passwd and then password to give the root user a password
  • nano /etc/ssh/sshd_config with the following edit to allow root user ssh login
    • Find the (commented out) line #PermitRootLogin prohibit-password and without modifying it, add the following new line below it
    • PermitRootLogin yes
    • Ctrl-X, y, Enter to save the changes and exit nano
  • service ssh reload to reload the ssh daemon configuration
  • attempt to log in via a new ssh session as root, in order to verify if all is OK.

At this point:

  • cut -d: -f1 /etc/passwd should list USERNAME as the last entry.
  • cut -d: -f1 /etc/group should list USERNAME as the last entry.
  • id (when executed as USERNAME) should return uid=1000(username) gid=1000(username) groups=1000(username),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lxd)

Now delete the user USERNAME:

  • deluser --remove-home USERNAME to delete the user created during installation. You will get a warning Warning: group 'USERNAME' has no more members., but this group will also be deleted automatically before the command finishes.

At this point:

  • No user named USERNAME should be listed in cut -d: -f1 /etc/passwd.
  • No group named USERNAME should be listed in cut -d: -f1 /etc/group.
  • It is possible to log in via ssh as the user root with the root password.

While it may be the case that some stuff still refers to USERNAME, the way the system is at this point comes relatively close to what a VPS would offer, hopefully close enough to do some testing with Ansible or similar.

While that Kickstart-solution should be the correct one, this one may be easier to archive and offer nearly the same functionality.

Related Question