Ubuntu server installation with root only?
Solution 1
You can use Kickstart configuration to disable creating the user at installation.
There is an option for that : #d-i passwd/make-user boolean false
Kickstart will be able to help you create VPS like images on different servers, it is usually used to install server's that are exactly alike.
Solution 2
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
- Find the (commented out) line
-
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 listUSERNAME
as the last entry. -
cut -d: -f1 /etc/group
should listUSERNAME
as the last entry. -
id
(when executed asUSERNAME
) should returnuid=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 warningWarning: 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 incut -d: -f1 /etc/passwd
. - No group named
USERNAME
should be listed incut -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 videos on Youtube
Jean-Philippe Murray
Updated on September 18, 2022Comments
-
Jean-Philippe Murray over 1 year
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 ;-)
-
Byte Commander over 6 yearsYou could simply unlock the root account (by setting a password for it) and delete your standard sudo user account after the installation. I don't know how complex it would be to modify an installer image that way, but the manual method is definitely much simpler and also shouldn't take long.
-
Jean-Philippe Murray over 6 years@ByteCommander you're right. I too often neglect the easy solution that's sitting in front of me!
- I know running on