Home > Blockchain >  Can't ssh into EC2 instance if I set my user to sudo: true in cloud-init
Can't ssh into EC2 instance if I set my user to sudo: true in cloud-init

Time:09-23

The following yml script initiates an EC2 instance which allows me to login with the .pem file corresponding to the ssh_authorized_keys.

  - name: myuser                                                                
    primary_group: mygroup                                                       
    sudo: false                                                                
    lock_passwd: true                                                          
    ssh_authorized_keys:                                                       
      - ssh-rsa ALDLKDSDF...

However, if I set sudo: true, the instance won't let me ssh (authentication failed). The same is true if I also set lock_passwd: false. Any ideas?

CodePudding user response:

From Cloud config examples — cloud-init documentation:

#   sudo: Defaults to none. Accepts a sudo rule string, a list of sudo rule
#         strings or False to explicitly deny sudo usage. Examples:
#
#         Allow a user unrestricted sudo access.
#             sudo:  ALL=(ALL) NOPASSWD:ALL
#
#         Adding multiple sudo rule strings.
#             sudo:
#               - ALL=(ALL) NOPASSWD:/bin/mysql
#               - ALL=(ALL) ALL
#
#         Prevent sudo access for a user.
#             sudo: False
#
#         Note: Please double check your syntax and make sure it is valid.
#               cloud-init does not parse/check the syntax of the sudo
#               directive.

Therefore, there is no true option for sudo.

  • Related