Results 1 to 4 of 4

Thread: runing script as new user during cloud-init

  1. #1
    Join Date
    Apr 2024
    Beans
    2

    runing script as new user during cloud-init

    I am new to use cloud-init to automate the installation of Ubuntu22.04. I am now able to install the OS by using the cloud-config below
    Code:
    #cloud-config
    autoinstall:
      version: 1
      apt:
        primary:
        - arches: [default]
          uri: http://freenas.boot.pxe:9081/repository/apt-proxy/
      user-data:
        timezone: Asia/Shanghai
        disable_root: true
      identity:
        hostname: ubuntu
        password: $6$FhcddHFVZ7ABA4Gi$r9wyPRFCtp1fL28aj6C9G4GIePSfqqUDVJAq7.qAtookMeYJCY6NH7TF19NZHk.x0ign7Y7Xgh3JEGcXVfozH1
        username: oai 
      keyboard: {layout: us, variant: ''}
      locale: en_US.UTF-8
      ssh:
        install-server: true
      packages:
        - htop
        - iftop
        - curl
        - git
        - gnupg-agent
      storage:
        layout:
          name: direct
      late-commands: 
        - curtin in-target --target=/target -- wget -O /usr/local/bin/post_script.sh http://freenas.boot.pxe:8080/PXE/Preseed/post_script.sh
        - curtin in-target --target=/target -- chmod +x /usr/local/bin/post_script.sh
        - curtin in-target --target=/target -- /bin/bash /usr/local/bin/post_script.sh
    During the installing, a new user named "oai" is created and post configuration script "post_script.sh" is downloaded to the target and executed. However, when executing the post_script, it cannot see the newly created user "oai". A simple script below will throw an exception says user "oai" is not exist.
    Code:
    #!/bin/bash
    
    mkdir -p /home/oai
    chown oai:oai /home/oai
    It seems that the user "oai" is not yet created when running late-commands. It is the right place the put the post configuration script in late-command? Is there any other way to set the owner of a file/path to the newly created user rather than root during the cloud-init process.

    Thanks.

  2. #2
    Join Date
    May 2010
    Beans
    3,276

    Re: runing script as new user during cloud-init

    Can you set the UID in the code, then set it using the UID? Does that work?

  3. #3
    Join Date
    Mar 2010
    Location
    USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: runing script as new user during cloud-init

    Cloud-init is executed as root. Yiu can set user permissions and user or group ownership's as root. It there s problem with that concept in itself?

    I tend to put more value on group memberships, for things that need to be shared beyond a single user. May be just me, but there is a big difference between a personal computer, and server(s) with clients infrastructure... And what sense to implement it's support.
    Last edited by MAFoElffen; 4 Weeks Ago at 05:35 AM. Reason: Type/spelling.

    "Concurrent coexistence of Windows, Linux and UNIX..." || Ubuntu user # 33563, Linux user # 533637
    Sticky: Graphics Resolution | UbuntuForums 'system-info' Script | Posting Guidelines | Code Tags

  4. #4
    Join Date
    Apr 2024
    Beans
    2

    Re: runing script as new user during cloud-init

    Quote Originally Posted by ActionParsnip View Post
    Can you set the UID in the code, then set it using the UID? Does that work?
    chown using uid/gid works. Thank you!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •