Linux: Delete user password command

I am a new Linux user. I would like to disable a password for an account. How do I delete user Password under Linux operating system using command line option?

All user passwords are stored in /etc/shadow file. The quick way to remove/delete a user password is pass --delete option to the passwd command. First, login in as a root user using sudo command/su command and type the following command:

ADVERTISEMENTS

Command to delete user password under Linux

Type the following command to delete a user password:
# passwd --delete username
OR
# passwd -d username
OR
$ sudo passwd -d sweta
Removing password for user sweta.
passwd: Success

Above command delete a user’s password (make it empty). This is a quick way to disable a password for an account. It will set the named account passwordless. User will not able to login. It is also a good idea to setup user shell to nologin to avoid security related problems:
# usermod -s /usr/sbin/nologin usernameFor example to delete password for user sweta, Type:# passwd -d sweta
# usermod -s /usr/sbin/nologin sweta

Verification

Use the following chage command/grep command (feel free to replace the username sweta with actual username):
# chage -l sweta
# grep sweta /etc/passwd
# grep sweta /etc/shadow

Sample session:

Fig.01: All commands in action

Fig.01: All commands in action

See also:

🐧 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
19 comments… add one
  • hemant May 28, 2007 @ 7:19

    I have a Doubt,I want ssh and sftp to remote machine without asking password.

    I did lots of thing according to the net help but it is still asking password.

    I did on server as follows

    1) ssh-keygen -t dsa; ssh-keygen -t rsa
    2) copied it on remote host in my home dir. /.ssh/authorized_key
    but it is asking password
    3) on server i gave command ssh-agent $SHELL and ssh-add
    some simple mistake is there but i am not able to find out could anybody help me out.

    • Herberth Amaral Dec 28, 2010 @ 10:37

      The filename is “authorized_keys”, in plural :-)

  • hemant May 28, 2007 @ 7:21

    if 3/4 client machines are connected to a solaris server,what would be the command to know that each and every client machine using the memory and other resources of the server and upto what %

  • 🐧 nixCraft May 28, 2007 @ 14:43

    hemant,

    You are posting questions to wrong topic, anyway join our forum and post your question in appropriate thread.

    For ssh see this FAQ

  • miranda starling Dec 15, 2007 @ 23:42

    i need help on deleting my myspace account i lost my password on there.. and i need it deleted so i can put a new one up there,

    i would appreciate any tips thankz
    miranda s

  • sunilkumar May 21, 2009 @ 10:35

    plese send shortcut command in my email id .

  • Nik Jan 2, 2010 @ 15:18

    nice one, though I did not require the nologin part, now I can log in without password.

  • Randy Jul 11, 2010 @ 16:12

    UHm. I tried this but this it says permission denied .. and this is the only account on this ubuntu. So I’m lost :S

    • luke Dec 25, 2014 @ 11:36

      Use the ‘sudo’ command (without quotes) before the commands, for example, to delete password for user sweta, Type:
      # sudo passwd -d sweta
      # sudo usrmod -s /sbin/nologin sweta
      if it still doesn’t allow you to, then edit the following file: /etc/sudoers
      there are many articles about this on forums. Basically find all lines like this:
      yourusername ALL=(ALL:ALL) ALL
      or
      %yourgroupname ALL=(ALL) ALL
      and change ALL=(ALL:ALL) ALL (and) ALL=(ALL) ALL
      (to) ALL=(ALL) NOPASSWD:ALL
      (and) ALL=(ALL:ALL) NOPASSWD:ALL
      also, make sure the
      #includedir /etc/sudoers.d
      line has to hashes (##)
      hope the long post helps.

  • antoni Sep 30, 2010 @ 14:26

    this si how my line looks like:
    sudo passwd -d username

    it worked, but my friend forgot to type sudo, (read everything before starting :P)

  • felix May 28, 2011 @ 18:24

    i forgot password on linux cp, DELL is there any way to get in my account without password

  • masum Aug 13, 2011 @ 9:04

    i am a user of linux.but i forget my linux password please help me to delete passwogr

  • anonymous Apr 29, 2014 @ 19:26

    The following line:

    It will set the named account passwordless. User will not able to login.

    is inaccurate, at least on Centos 6.x. This page should make it very plainly clear that disabling a password disables password checking and does NOT disable the account. On the console, this means you can log in with no credentials. PAM likely prevents this from working with SSH in default configurations, but PAM is not always configured for sshd.

    • Hareesh Joshi Jun 28, 2016 @ 5:14

      Yes, this is right. Even I observed exactly what you did. It resets the password to blank and doesn’t prevent the user from logging in.
      OS: CentOS 6.7 and higher

  • luke Dec 25, 2014 @ 11:18

    This worked for me, i think, although I also edited the sudoers file so im not sure which is to blame.

  • Bairo Aug 16, 2015 @ 13:12

    I Am using Acer C70 with Manjaro Linux Xfce 64 bit. I forget my password. I want to remove the password but maintain the account without password. Any help please. am a newbie.

  • Jouni "rautamiekka" Jrvinen Aug 26, 2017 @ 12:25

    usrmod should be usermod.

  • Bathinda Helper Aug 31, 2020 @ 13:09

    Great article.
    Two doubts:
    You said: “It will set the named account passwordless. User will not able to login.” What does it mean? If a user without any password can’t login at all, isn’t there a way around?

    2nd, you said, “For verification: Use the following chage command/grep command”
    What does this grep command verify, and how? What would we need to see to verify?

    Thanks.

Leave a Reply

Your email address will not be published.

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