How to Create New User in ESXi With Shell Script

It’s pretty easy to create a new user using vSphere APIs in Java. If you want one or two lines of scripts, you can write a few line Python script using PyVimomi wrapped by a command line. Even easier is a solution discussed at PureVirtual.

The trick is really about how to access the adduser command, which is available but not accessible from console as it is. To use the command, you have to type the following command from ESXi console: (I assume there are a few more commands that can be used in the same way)

Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.

# /usr/lib/vmware/busybox/bin/busybox adduser -s /bin/sh -G root -h / steve

The -s defines the shell; -G defines group; -h defines home directory. The last argument is the name of the user to be added. Upon typing the command, you will be prompted for new password. This interaction is fine for manual process, but not OK for full automation.

Luckily there is a switch -D that indicates no password to be defined, but not so lucky with including password directly, for example,

# /usr/lib/vmware/busybox/bin/busybox adduser -s /bin/sh -G root -h / -D steve

Although the command goes through without asking for password, it’s not a good idea to leave the user without password. So you got to change the password right afterwards.

After researching it and inspired by a stackoverflow discussion, I got the following script working. It changes the password for user “steve” to “doublecloud”. There is no need to include the busybox path there, so the script is shorter. :)

# echo doublecloud | passwd steve --stdin

Combined the above commands together, we can have a fully automated script that creates a new user in ESXi without leaving the password open.

Still, the API way is the preferred way to create a new user. If you can go with the API approach, just do it; otherwise the above pure shell scripting works just fine.

This entry was posted in Virtualization and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.


  1. Kevin
    Posted May 18, 2015 at 5:40 am | Permalink

    Thank you very much – very helpful indeed.

  2. Posted May 18, 2015 at 11:26 am | Permalink

    Glad that you find it helpful. -Steve

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


    My company has created products like vSearch ("Super vCenter"), vijavaNG APIs, EAM APIs, ICE tool. We also help clients with virtualization and cloud computing on customized development, training. Should you, or someone you know, need these products and services, please feel free to contact me: steve __AT__

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.