How to enable or disable a user?

I'm uing ubuntu 12.04 desktop. I have 3 users: user1(administrator), user2(standard) and guest. I wanted to disable user1 and enable user2 which auto logs on with no password but after I did that I can't login to user1 and user2 accounts except the guest session user. I'm striped off every administrative privileges. I don't know which options are available to me and how do I enable root or user which is an administrator?


Solution 1:

Expire Account

Let the account expire to disallowing a user from logging in from any source including ssh:

# disallow peter from logging in
sudo usermod --expiredate 1 peter

This is how you can reenable that account:

# set expiration date of peter to Never
sudo usermod --expiredate "" peter

Lock a Password

To disable / lock the password of user account use below command. This will not disallow ssh-access on Ubuntu. This prepends a ! to the password hash so that no password will match it anymore.

# take away peters password
sudo passwd -l peter

To unlock him:

# give peter back his password
sudo passwd -u peter

Expire a Password

This command seems to differ across platforms. On Ubuntu, expiring a password will command the user to make up a new one once he logs in. This is not suitable for disabling an account.

# make peter think of a new password on login
sudo passwd -e  YYYY-MM-DD peter

Solution 2:

Use this to lock an account:

sudo usermod -L -e 1 [username]

and this to unlock an account so locked:

sudo usermod -U -e "" [username]

Solution 3:

Note:

(Disabling and locking a user account both mean the same thing.)

To disable / lock the user account use below command:

sudo passwd -l [user_name]

e.g.

sudo passwd -l samual

To put an expire date to an user account so that it automatically gets disabled / locked.

sudo passwd -e  YYYY-MM-DD [user_name]

e.g.

sudo passwd -e  2013-05-31 samual

To re-enable a disabled user, issue the passwd command with the -u option.

sudo passwd -u [username]

e.g.

sudo passwd -u training

To enable the root account and change the root password use below steps.

1) su -
2) passwd

Enter the new password for root account and then exit. if this does not solve the issue let me know.

Please feel free to let me know if you need anything else or any further clarification.