I am new to Linux and I am using Centos7 from AWS and I am slightly confused. To my understanding, in order to use sudo, you need to be in sudoers and by default, the root user and group wheel are in sudoers. I am currently the centos user and I can use sudo, but I can't understand why. I don't believe I am in the group wheel.
1 Answer
In cloud environments, many distributions (including CentOS 7) use cloud-init to configure the system when it first boots.
If we look at /etc/cloud/cloud.cfg
on the CentOS 7 cloud image, we find:
system_info:
default_user:
name: centos
lock_passwd: true
gecos: Cloud User
groups: [wheel, adm, systemd-journal]
sudo: ["ALL=(ALL) NOPASSWD:ALL"]
shell: /bin/bash
distro: rhel
paths:
cloud_dir: /var/lib/cloud
templates_dir: /etc/cloud/templates
ssh_svcname: sshd
This says, "create a user named centos
and apply the sudo
configuration ALL=(ALL) NOPASSWD:ALL
to that user. This causes cloud-init
to create the file /etc/sudoers.d/90-cloud-init-users
with the content:
# Created by cloud-init v. 18.2 on Mon, 08 Aug 2022 22:07:23 +0000
# User rules for centos
centos ALL=(ALL) NOPASSWD:ALL
And that is why the centos
user has sudo
access.
sudo
?/etc/sudoers.d
for any included files.