On an Amazon Linux 2 EC2 instance, password authentication from remote users has been enabled by running the following command during the
cloud-init startup script:
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config . As a result, remote users do not use a keypair to authenticate when logging in to the Amazon Linux 2 EC2 instance. One of those users,
someuser , needs to be able to run
sudo commands without typing in a password.
Cloud-Init Startup Script
cloud-init startup script is as follows:
/usr/sbin/useradd someuser echo someuser:some-password | chpasswd sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config systemctl restart sshd cat << 'EOF' > /etc/sudoers.d/someuser someuser ALL=(ALL) NOPASSWD: ALL EOF
What specific syntax needs to be used in the above
cloud-init startup script in order to enable
someuser to run
sudo commands without restating their password, but while still enabling
someuser to login remotely via Putty using their given password?
The error message
The following screen shot illustrates the error message:
Toggling The Error
The above current syntax results in
someuser not being able to Putty in due to a lack of a Public key. However, the error can be removed, so that
someuser is able to log in, but is NOT able to perform
sudo commands, if the 3 line
cat command is commented out of the above:
#cat << 'EOF' > /etc/sudoers.d/someuser #someuser ALL=(ALL) NOPASSWD: ALL #EOF
The problem is in the preceding 3 lines posted here at the end. How can these 3 lines be rewritten, replaced, or augmented to enable this user to elevate to
sudo without a password while still retaining the ability to Putty in using only a password?