Author Topic: [SOLVED]how to show password when entering it?  (Read 492 times)

Offline snork

  • Full Member
  • ***
  • Posts: 113
[SOLVED]how to show password when entering it?
« on: January 20, 2012, 02:24:22 PM »
When I setup a user on a system, I use 'useradd' and 'passwd'. Using 'passwd' command doesn't show the characters I type, making it tedious to enter long and cryptic passwords for users.

Is there some way to allow me to see what I type in when setting up the password for a new user?

I've tried the old 'echo username:new_pw | chpasswd, which allow me to see what I type, but that command chokes when you use either the '&' or the '!' character in a password, which I believe are allowed special characters.
« Last Edit: January 20, 2012, 05:01:32 PM by snork »

Offline AS

  • Hero Member
  • *****
  • Posts: 4098
  • Have a nice ... night!
Re: how to show password when entering it?
« Reply #1 on: January 20, 2012, 03:14:33 PM »
When I setup a user on a system, I use 'useradd' and 'passwd'. Using 'passwd' command doesn't show the characters I type, making it tedious to enter long and cryptic passwords for users.

Is there some way to allow me to see what I type in when setting up the password for a new user?

no that I'm aware, hiding the password is considered a feature.

Quote
I've tried the old 'echo username:new_pw | chpasswd, which allow me to see what I type, but that command chokes when you use either the '&' or the '!' character in a password, which I believe are allowed special characters.
The problem here is that the shell is an interpreter, and several characters have special meaning,
if the character where only '&' and '|' the problem could have been solved by "quoting" the strings, like follow:
Quote
echo "username:new_pw" | chpaswd
unfortunately this will chokes when a 'double quote' ( " ) would be used in the password strings, and others characters too.

An alternate method could be to redirect the input to a temp file containing username:password and then using
Quote
chpasswd < tempfile
... provided that you will redirect the "typed in" password without using the shell functions ...
but this will increase the risk, as minimum precaution you should use some secure delete function to overwrite the temp file once the job is done.

Not a very good idea to show out passwords  ::)

AS



Offline snork

  • Full Member
  • ***
  • Posts: 113
Re: how to show password when entering it?
« Reply #2 on: January 20, 2012, 03:49:11 PM »
Thanks for the responses. That gave me some ideas to try.

Is there some way to use --stdin with that last suggestion (chpasswd < tempfile) instead of creating a tempfile? e.g. chpasswd < user:pw --stdin

I know showing passwords is not a good idea, but when you have to enter 40 users at once and the passwords are 30 characters or more long, with a ton of special characters in them, it's easy to mis-type something, reading the passwords from a piece of paper or email.

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11688
  • ----IOFLU----
Re: how to show password when entering it?
« Reply #3 on: January 20, 2012, 04:03:53 PM »
Thanks for the responses. That gave me some ideas to try.

Is there some way to use --stdin with that last suggestion (chpasswd < tempfile) instead of creating a tempfile? e.g. chpasswd < user:pw --stdin

I know showing passwords is not a good idea, but when you have to enter 40 users at once and the passwords are 30 characters or more long, with a ton of special characters in them, it's easy to mis-type something, reading the passwords from a piece of paper or email.

Now you know the reason you get the "big bucks" ... nobody else wants your job...  ;D ;D ;D
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline AS

  • Hero Member
  • *****
  • Posts: 4098
  • Have a nice ... night!
Re: how to show password when entering it?
« Reply #4 on: January 20, 2012, 04:23:20 PM »
Thanks for the responses. That gave me some ideas to try.

Is there some way to use --stdin with that last suggestion (chpasswd < tempfile) instead of creating a tempfile? e.g. chpasswd < user:pw --stdin

I know showing passwords is not a good idea, but when you have to enter 40 users at once and the passwords are 30 characters or more long, with a ton of special characters in them, it's easy to mis-type something, reading the passwords from a piece of paper or email.

Quote
read  -p  "username: "  X  ;  read  -p  "password: "  Y  ;  echo  "$X:$Y"  |  chpasswd

or, if running directly from a logged user:
Quote
read  -p  "password: "  Y  ;  echo  "$LOGNAME:$Y"  |  chpasswd

 ;)
« Last Edit: January 20, 2012, 04:53:37 PM by as »

Offline snork

  • Full Member
  • ***
  • Posts: 113
Re: how to show password when entering it?
« Reply #5 on: January 20, 2012, 05:00:56 PM »
Old-Polack, If I'm getting the big bucks, they must be sending them to the wrong address. ;)

AS, Those suggestions look very interesting. I'll have to try them the next time I have to create new users.

Thanks a lot.

I'm going to mark this as solved since those look like they will work.