It is easy to change the password for a local user, just type:
and follow the instructions.
But, when we have to change password remotely, things became more complicated. We can make login in each server and change the password manually as explain before,  or change the password remotely using ssh as connection mode, saving time and effort, that we can spend in other tasks. Let’s see how to do it.

root user

If we are root, the solution can be very simple, we will use the command passwd with the option --stdin

–stdin:

This option is used to indicate that passwd should read the  new  password
from standard input, which can be a pipe.

So the command to change the password of user1 to newPassword would be like this:

If the command passwd doesn’t have the option --stdin, because the version,  we can use the following method for non root users.

Non root user

If we are not root, we cannot use --stdin option from passwd, so we have to modify the command a little.

  • non root user, only can change their own password,
  • they have to type the current password
  • they have to type the new password twice
  • accomplish the password policies, that root can ignore.

 

So to accomplish this requirements, we can use the option -e from echo command, that allow us to use the new line code \n , so we can pass to command passwd the input expected without the --stdin option.

-e:

 enable interpretation of backslash escapes

So finally the command to change the password of user1 to newPassword would be like this:

Put into practice

Let’s see an example where we have to change the password for user1 to oth3r0n3 in five servers, we will use CollectNode to execute the command in all servers quickly and get the command results for each server.

first of all we add the servers name to the file hosts.txt

And now we will use the command for root user:
changing user password remotely

Get CollectNode now !

Leave CollectNode to make the hard work, and spend your time where really matters.
Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Pin It on Pinterest

Share This

Share This

Share this post with your friends!