LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-11-2006, 10:53 PM   #1
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Rep: Reputation: 15
Can a user login without having a password set?


Hi again friends!


I'm happy to report that no serious problems are bugging me this time, just curious.

I'm having an argument with one of my pals about whether a user would be able to gain access into Nix if his/ her account was created via "useradd -d /home/dummy -m -s /bin/bash -c "Dummy User" dummy".

Usually I'll set the password directly afterwards by doing a "passwd dummy" and entering the password. After that I know the user will be able to login.

Now the argument is that if no password was set afterwards via passwd, would the user be able to login? My stance is no. My pal says yes.


Am I right here or do I owe my friend a beer?

Last edited by kinetik; 07-11-2006 at 11:00 PM.
 
Old 07-12-2006, 01:05 AM   #2
zetabill
Member
 
Registered: Oct 2005
Location: Rhode Island, USA
Distribution: Slackware, Xubuntu
Posts: 348

Rep: Reputation: 32
Quote:
Originally Posted by kinetik
I'm having an argument with one of my pals about whether a user would be able to gain access into Nix if his/ her account was created via "useradd -d /home/dummy -m -s /bin/bash -c "Dummy User" dummy".

Usually I'll set the password directly afterwards by doing a "passwd dummy" and entering the password. After that I know the user will be able to login.

Now the argument is that if no password was set afterwards via passwd, would the user be able to login? My stance is no. My pal says yes.

Am I right here or do I owe my friend a beer?
You get to keep your beer my friend.

If you use useradd with those options and not getting asked the questions, passwd is not invoked automatically for you like normal. If you do not invoke passwd after creating an account in that fashion, then the account will be locked until root issues a password. Therefore making the account unusable by anyone. (All logins will fail)

Here is some info you might find useful:
At anytime you can use
Code:
passwd -l dummy
to lock any account other than root. It "scrambles" the entry in /etc/shadow to something ridiculous and unguessable, making the account unusable. If you want to restore the password to the value that existed before you locked it, you would issue
Code:
passwd -u dummy
and the password is usable again. That probably wouldn't be very good in the case of a newly created account because you want some control over it. If you don't want to give the account a password at all, even after creating it, you would do:
Code:
passwd -d dummy
This deletes whatever entry is in /etc/shadow for the dummy account. It doesn't matter if you never set the password (as in your question) or if it's locked or unlocked, the password is deleted and the login will not ask for a password.

If you feel a bit daring, there is a way to set the password with useradd:
Code:
useradd -p <passwd> dummy
If the -p option isn't there, then the default action is to lock the account. But the man page for useradd tells that <passwd> value is returned by the crypt function.

I'm not playing with that. But if you can figure it out let me know.

Enjoy that beer!

EDIT: All those commands as root... of course...

Last edited by zetabill; 07-12-2006 at 01:06 AM.
 
Old 07-12-2006, 01:06 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by kinetik
Hi again friends!
Now the argument is that if no password was set afterwards via passwd, would the user be able to login? My stance is no. My pal says yes.

Am I right here or do I owe my friend a beer?
You win---but, you CAN set it so the new user can log in with no password. Edit the /etc/passwd file and remove the first "x" after the username. Now that user can get in with no password.

Here's the /etc/passwd entry for "dummy" with no password required:
Code:
dummy::503:505::/home/dummy:/bin/bash
 
Old 07-12-2006, 04:42 PM   #4
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Original Poster
Rep: Reputation: 15
A-ha! Thought I was right!


Thanks ZetaBill and Pixellany, your replies are much appreciated as always. I'll keep the beer I would've bought my pal and e-mail each of you one (wish that was possible).


Thanks buddies!
 
Old 07-12-2006, 07:55 PM   #5
zetabill
Member
 
Registered: Oct 2005
Location: Rhode Island, USA
Distribution: Slackware, Xubuntu
Posts: 348

Rep: Reputation: 32
Quote:
Originally Posted by pixellany
Edit the /etc/passwd file and remove the first "x" after the username. Now that user can get in with no password.

Here's the /etc/passwd entry for "dummy" with no password required:
Code:
dummy::503:505::/home/dummy:/bin/bash
I never knew that! Learning all the time...

warning...

I love the simplicity of directly changing the passwd file to rid the user's password. But that can't be accomplished in a bash script without some use of awk or sed. It's easier to use 'passwd -d' and it does the same thing.

I would not have known that passwd -d does the same thing has removing the 'x' in the password field in /etc/passwd if pixellany had not got me interested.

The only reason I bring it up is that a professor once showed me his script that he ran when he got his student list every semester. That's what kinetik's useradd invokation reminded me of. It used most of the switches at the end of the useradd statement and took the values from a student file via the read statement, variables, and a do loop. Before the do loop ended he also ran passwd with some ingenious mathematical method of making passwords.

So kinetik, if you want to accomplish your task, in one line, you could do something like this
Code:
useradd -d /home/dummy -m -s /bin/bash -c "Dummy User" dummy; passwd -d dummy
and you would create the account without having it be locked, without the need to supply a password, and without having to answer any questions.

I only offer this because I assume that if you're using useradd with the options rather than going through the questions it asks you, that you're attempting to save as much time as possible or you'd be writing a bash script.

I might have too much time on my hands... but I had fun. I might get a beer of my own now.
 
Old 07-13-2006, 04:38 PM   #6
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by zetabill
I might have too much time on my hands... but I had fun. I might get a beer of my own now.

Dude, I owed you one before already so your tally's up to two now (at the rate we're going we'd have polished a crate before the end of the week )


Thanks buddy!
 
Old 07-25-2009, 01:17 PM   #7
MrUmunhum
Member
 
Registered: May 2006
Location: Mt Umunhum, CA, USA, Earth
Distribution: Debian/ Fedora/ Ubuntu/ Raspbian
Posts: 549

Rep: Reputation: 40
This does not work for Ubuntu

Quote:
Originally Posted by zetabill View Post

I love the simplicity of directly changing the passwd file to rid the user's password. But that can't be accomplished in a bash script without some use of awk or sed. It's easier to use 'passwd -d' and it does the same thing.
Too bad, nice trick. Works for Fedora. Debian must have FIXED it?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to login if I didnt set a root password and no user? lonecrow Linux - Newbie 7 05-14-2006 07:56 PM
HOW-TO? Create User, Set Password with script longtex SUSE / openSUSE 13 10-02-2005 02:35 PM
Unable to set password for user Harlin Linux - General 2 09-20-2005 01:25 PM
User login without password Artik Debian 5 05-11-2005 12:56 PM
vsftpd how to set password and user? djkoe Linux - Newbie 3 12-30-2003 08:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration