How to change root password on macOS Unix using terminal

I am a new user of macOS Unix running on MacBook Pro and Mac mini server. I need to change the password for root user account on macOS. How do I change the root password on macOS Unix using command line options?

Introduction – You need to use the passwd command. It is used to update the user’s authentication token(s) i.e. password. Let us see how to change the root user password on macOS Unix.

ADVERTISEMENTS

How to change root password on macOS Unix

The procedure for changing the password of root is as follows:

  1. First, log in to the macOS Unix server using ssh or console or terminal app
  2. Open a shell prompt/terminal app and type the passwd command to change root password in macOS Unix
  3. The actual command to change the password for root on macOS Unix is sudo passwd root

NOTE: Please note that mbp:~ vivek$ is my shell prompt. You need to type commands after the $ prompt.

macOS Unix change root password command

I am going to log in to my macOS based mac mini server using the ssh command:
ssh vivek@macmini-server
If you are using a macbook/MBP, just open the terminal app. Once logged in enter the command passwd as follows:
mbp:~ vivek$ sudo passwd root
First you need to type the password for vivek user. After that the passwd command asks for the new password, which you will have to enter two times:

Changing root account passwords on an RHEL based system

Changing root account passwords on macOS

The next time you log in to a macOS Unix server/workstation, use the new password for root user.

Slightly different procedure for changing passwords in macOS Unix terminal

One can use the following procedure too:
mbp:~ vivek$ ssh user@your-mbp-macmini
Become a root user via the su command or sudo command:
your-mbp-macmini:~ vivek$ sudo -i
Finally change your root user password:
passwd

More on passwd command

The passwd command changes the user’s password. For example, change your own password using the Terminal app, run:
passwd
To change password for user named jerry, run:
sudo passwd jerry

Conclusion

This page explained the process for changing the password of root user using the passwd command on a macOS Unix system. For more information see the passwd command man page by typing the following man command:
man 1 passwd
man 5 passwd

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.