Wednesday, April 11, 2012

Set User Password using single command line in Linux

To set "Linux User" password using single command line.

On your shell prompt, type below command.
echo -e "Hello\nHello" | passwd nishith

Here,
-e : effect
\n : New Line
Hello : Mentioned twice as "password & retype password" ;)
nishith : User Name

Change the password of "nishith" users on a bunch of servers i.e. 10-20 servers.

Let's say server ip address range is from "192.168.10.1 to 192.168.10.20"

On your shell prompt, type below command.

for ((i=1,i<=20;i++); do ssh 192.168.10.$i 'echo -e "Hello\nHello" | passwd nishith'; done;

Create one user & set it's initial password remotely.

ssh 'useradd ; echo -e "passwdofuser\npasswordofuser" | passwd newuser'

Example:

ssh root@192.168.10.10 'useradd nishith1; echo -e "Hello1\nHello1" | passwd nishith1'

It will ask "root" password of 192.168.10.10 & rest will be taken care by the command itself.


Enjoy Linux