Skip to contentSkip to conversation

Change password with usermod

DISCUSSION Mário Gamito 3 participants 5 messages Mar 10, 2007

lore
Share & tools
lore
#0 lore raw

Hi,

I'm trying to set a password directly from a script, using usermod, but i get an error, i shouldn't get:

#!Bin/bash
groupadd postgres
useradd -g postgres postgres
PASS=mkpasswd secret
ID=cat /etc/passwd | grep postgres | cut -f3 -d':' usermod -p $PASS -u $ID

This gives me:
"usermod: user 502 does not exist"

But the odd thing is that it exists with that uid.

Any ideas ?

Warm Regards,
Mário Gamito
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Mário Gamito

Hi,

Quoted 6 lines · Mário Gamito

PASS=mkpasswd secret
ID=cat /etc/passwd | grep postgres | cut -f3 -d':' usermod -p $PASS -u $ID

This gives me:
"usermod: user 502 does not exist"

usermod needs a login name rather than the userid and you don't need -u option:

# usermod -p $PASS postgres

However, I usually user chpasswd to change the password from a script, so your script becomes:

# echo postgres:secret | chpasswd

Hope this helps,
Krzysztof

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Hi,

Thank you for your answer.

Quoted 4 lines

usermod needs a login name rather than the userid and you don't need -u option:

# usermod -p $PASS postgres

I tried that but didn't work for me:
"[root@mail ~]# usermod -p $PASS postgres
usage: usermod [-u uid [-o]] [-g group] [[-a] -G group,...]

                [-d home [-m]] [-s shell] [-c comment] [-l new_name]
                [-f inactive] [-e expire ] [-p passwd] [-L|-U] name"
Quoted 4 lines

However, I usually user chpasswd to change the password from a script, so your script becomes:

# echo postgres:secret | chpasswd

But this does :)

Thanks a bunch.

Warm Regards,
Mário Gamito
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
In reply to Krzysztof Dubowik
Quoted 4 lines · Krzysztof Dubowik

However, I usually user chpasswd to change the password from a script, so your script becomes:

# echo postgres:secret | chpasswd

A better idea is to:

# chpasswd < passfile

where passfile has been created with the contents:

postgres:secret

That prevents your new password from appearing momentarily in the process list during this procedure.

—IWC

-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html