Linux menu

Wednesday, September 24, 2014

Change Hack Users Passwords(chpasswd) For Easy Admin In Linux

Creating users and managing passwords is one of the primary responsibilities of a system administrator. A good policy requires modification of passwords on regular intervals. But changing the passwords for a number of users with passwd command becomes difficult. In this article we provide a method to change the passwords in batch mode.

1. The chpasswd command:

The command chpasswd is used to modify the passwords in batch mode. Only root user can execute this command. It takes the passwords in the following format:
user:password
This syntax and usage of the command will be explained shortly. For this article, we consider following 5 users for which passwords will be modified:
1) linoxide
2) bobby
3) kyle
4) steve
5) joy
We provide here two methods in which chpasswd command can be used to modify the passwords in batch mode:

1.1 Method1: (STDIN)

In this method, just issue the command chpasswd and then it will prompt for the user passwords. The passwords will be given in the format shown above.
Providing passwords via STDIN
After you have entered all the users and passwords, you need to hit ctrl+d to tell the chpasswd command that this is end of input. You will get back your prompt after hitting ctrl+d and the passwords will be changed.
Pressing ctrl+d to submit

1.2 Method2: (Input from file)

You can alternatively maintain a file that contains all the users and the passwords. We can then redirect the input from this file.
Let us go ahead and create a file with cat command (You can use other methods to create the file as well like vi or emacs editor):
Saving passwords in file
Now all we need to do is issue the command chpasswd with input redirected from the file:
Providing input via file

2. Command options:

2.1 Providing encrypted passwords:

There are various useful options to this command. You can provide the passwords already encrypted with -e or –encrypted option.
Providing encrypted passwords instead of plaintext

2.2 MD5 passwords:

The -m or –md5 option will encrypt the password using md5 algorithm.
Passwords will be encrypted with md5 algo

2.3 Other encryption methods:

The encryption algorithm to be used for passwords can be provided with -c or –crypt-method option. In the example, we use SHA512 as our encryption algorithm:
Provide custom encryption method

2.4 Command help:

As with most commands, the -h or –help will print out the command usage for chpasswd command.


No comments: