In this post learn how to set and reset user password by bash script on Linux systems. It is quite good for Linux System Admin who wants to know how to set and reset user account password with bash script. We have used the standard input (stdin) with passwd
command.
Advantage:
1. Get the list of users and reset/set their password at one time without password prompt. You do not have to type the passwd
command over and over in system.
2. By doing some more trick, you can randomly generate the password, set the password to user and send email at last with their credentials details.
Example 1: In this eg. we will create new user and set the passwd.
UserName : test
Passwd : test123
#!/bin/bash useradd test;echo test123|passwd test --stdin
Example 2: In this example we will reset the passwd.
Username: linuxtribe
Passwd : sort_1t_out
#!/bin/bash echo sort_1t_out|passwd linuxtribe --stdin