How to add user and change the password in SONiC

Table of Contents

Introduction

Welcome to the STORDIS Support Portal guide!

This article explains how to add a new user and change the password in SONiC.
SONiC is based on Debian Linux, which means standard Linux user-management tools are available.

You can add a new user and manage passwords using two different methods:

  • adduser (interactive, high-level command)
  • useradd combined with passwd (low-level, script-friendly approach)

 

adduser is a high-level, user-friendly frontend to useradd. Copies default configuration files from /etc/skel.

Example:

sudo adduser testuser

 

useradd is a low-level Linux command used to create user accounts.

Default settings are read from /etc/default/useradd and /etc/login.defs.

Example:

sudo useradd testuser

 

 Documentation:

adduser Debian Documentation

useradd Debian Documentation

passwd Debian Documentation

These resources provide detailed explanations of command options and configuration files.

 

Method 1 (adduser): Add a New User and Change the Password with One Command

Step 1: Login to SONiC. 

Default credentials:

Login: admin 

Password: YourPaSsWoRd

Step 2: Use the adduser command:

admin@sonic:~$ sudo adduser <username>

Step 3: Follow the interactive prompts to:

  • Set the password
  • Provide optional user information (full name, room number, etc.)

Remember!

This method is recommended for manual administration.

Example:

 

Method 2 (useradd, passwd): Add a New User and Change the Password

Step 1: Login to SONiC. 

Default credentials:

Login: admin 

Password: YourPaSsWoRd

Step 2: Create a new user:

admin@sonic:~$ sudo useradd <username>

Remember!

This command alone does not create a home directory or set a password.

Example:

 

A more complete example:

sudo useradd -m -s /bin/bash <username>

-m Create the user's home directory if it does not exist

-s Sets the path to the user's login shell

Step 3: Change the password for the current user:

admin@sonic:~$ passwd

Example:

 

Step 4: Change the password for a different user:

admin@sonic:~$ sudo passwd <username>

Example:

 

 

Best Practices

Security Considerations

  • Always assign a strong password to newly created users.
  • Avoid leaving user accounts without passwords.
  • Limit administrative (sudo) privileges to required users only.

Consistency

Choose either adduser or useradd and use it consistently across your system. This simplifies troubleshooting and user management.

Documentation

Keep records of:

  • Created usernames
  • Creation dates
  • Assigned groups
  • Purpose of each account

Good documentation improves security audits and long-term system maintenance.

 

Congratulations!

Hopefully this user and password management guide has proven useful.
Both adduser and useradd are valid tools - each suited to different use cases:

  • Use adduser for interactive, manual administration.
  • Use useradd for automation and scripting.

Which command do you prefer: adduser or useradd?

If you have any questions related to this article, feel free to reach out to our technical support team.

Happy Networking!

 

Useful links

If you want to explore more topics, be sure to check out our other guides, including:

How can I set up a console connection to Edgecore Open Networking switch?

Where to download the SONiC Virtual Switch (VS) community pre-built image?

For more free resources, visit: 

https://stordis.com/free-resources/

Still have questions? You can find more answers in our full FAQ - just follow the link below.

STORDIS Support Portal FAQ

Comments 0

Articles in this section