LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-07-2010, 09:26 AM   #1
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Rep: Reputation: 55
getent does not work for usernames with numbers


Hi All,

Here is the output of getent, which I am finding strange.

Code:
[3001@CDCTGIMCLSA ~]$ sudo getent passwd 3001
Also the exit status is 2

But the user 3001 exists in the system.

Code:
[3001@CDCTGIMCLSA ~]$ cat /etc/passwd | grep 3001
3001:x:513:513::/home/3001:/bin/bash
Also getent works well for usernames having alpabets.

Code:
[3001@CDCTGIMCLSA ~]$ sudo getent passwd test
test:x:511:511::/home/test:/bin/bash
I am finding it pretty amazing. Does anyone know why getent behaves like this ?
 
Old 09-07-2010, 10:27 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

Rep: Reputation: 62
what is the content of your /etc/nsswitch.conf file?
 
Old 09-07-2010, 11:30 AM   #3
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Quote:
Originally Posted by fpmurphy View Post
what is the content of your /etc/nsswitch.conf file?
Here is the contents of /etc/nsswitch.conf

Code:
passwd:     files
shadow:     files
group:      files
hosts:      files dns
bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files

netgroup:   files nis

publickey:  nisplus

automount:  files nis
aliases:    files nisplus
 
Old 09-08-2010, 07:29 AM   #4
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Any idea on this behavior of getent ?
 
Old 09-10-2010, 10:45 PM   #5
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
You probably should contact the programmer of the tool.
But I think that it will try to find a userid if the parameter is a pure numerical value in stead of trying to find a user with that
name.

Try using something like u3021
_______________
gerrard

Last edited by gdejonge; 09-10-2010 at 10:46 PM.
 
Old 09-10-2010, 10:50 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
try adding another user with numbers, eg useradd 3002. useradd will complain. Did you add 3001 using useradd? or did someone just create an entry in passwd ?
 
Old 09-10-2010, 11:24 PM   #7
mgsmith7475
LQ Newbie
 
Registered: Mar 2008
Location: Michigan
Distribution: RHEL 5.4 / Ubuntu 9.10
Posts: 8

Rep: Reputation: 0
Worked fine for me when adding a user by the name of 4000. just typed - getent passwd | grep 4000
and it found this - getent passwd | grep 4000
4000:x:525:527::/home/4000:/bin/bash

Definitely no bug.

Using Ubuntu 10.04

It also worked just fine on a RHEL 5.5 Server that I have available to me.

Last edited by mgsmith7475; 09-10-2010 at 11:45 PM.
 
Old 09-11-2010, 01:05 AM   #8
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by vinaytp View Post
Any idea on this behavior of getent ?
When you query numeric username it will search for uid not username

i.e when you run

sudo getent passwd 3001

it will detect 3001 as UID not username. if uid not present then your exit status return 2

quote from getent man page

Quote:
Each key must be in a format appropriate for searching on
the respective database. For example, it can be a username
or numeric-uid for passwd
So if you want to query numeric user names use their UIDs.

i.e

Code:
$ sudo getent passwd UID
HTH
 
Old 09-11-2010, 01:09 AM   #9
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by mgsmith7475 View Post
Worked fine for me when adding a user by the name of 4000. just typed - getent passwd | grep 4000
and it found this - getent passwd | grep 4000
4000:x:525:527::/home/4000:/bin/bash

Definitely no bug.

Using Ubuntu 10.04

It also worked just fine on a RHEL 5.5 Server that I have available to me.
Filtering from whole databse is ok but when you query for specific numeric user it will show exit status 2.

i.e try to run below command

Code:
getent passwd 4000
 
Old 09-13-2010, 01:17 AM   #10
vinaytp
Member
 
Registered: Apr 2009
Location: Bengaluru, India
Distribution: RHEL 5.4, 6.0, Ubuntu 10.04
Posts: 704

Original Poster
Rep: Reputation: 55
Thanks for all your comments.

We cannot add a user with username 3001 in fedora. But we can add in RHEL and CentOS.

So getnent is not working as expected when it comes to numerical usernames.

Can we consider this as a bug in getent?

Last edited by vinaytp; 09-13-2010 at 01:19 AM.
 
Old 09-13-2010, 02:29 AM   #11
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by vinaytp View Post
Thanks for all your comments.

We cannot add a user with username 3001 in fedora. But we can add in RHEL and CentOS.

So getnent is not working as expected when it comes to numerical usernames.

Can we consider this as a bug in getent?
when you query numeric username it consider as UID. read post #8.

It is not bug.
 
Old 09-14-2010, 01:02 AM   #12
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

Rep: Reputation: 62
Interestingly, I can add a user called "3001" in Fedora 13 without a problem.

But if I then use
Code:
getent passwd 3001
nothing is returned and the errno is 2.

System is standalone.
 
Old 09-14-2010, 03:07 AM   #13
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,036

Rep: Reputation: 96
I didn't think the system allowed you to create accounts (or groups) beginning with a numeric or special character.

I assume changing the usernames is out of the question?

It might be worth reviewing naming conventions to ensure that the issue doesn't get any worse (just a thought)
 
Old 09-14-2010, 03:34 AM   #14
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

Officially this is the legal template for a username: [a-z_][a-z0-9_-]*

Some distro's do allow other characters and might let you start a username with a number, but this could get you into trouble.

Hope this helps.
 
Old 09-15-2010, 06:49 AM   #15
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

Rep: Reputation: 62
Quote:
Originally Posted by druuna View Post
Hi,
Officially this is the legal template for a username: [a-z_][a-z0-9_-]*
What do you mean by officially? Where is that specified in any formal specification?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command getent return nothing aspenbr Linux - Software 1 11-18-2008 01:01 AM
getent passwd only pulls local info - getent group works? epoh Linux - Server 2 03-14-2008 08:56 AM
System usernames versus user numbers -- incompatibility? eater Linux - Software 4 03-01-2008 11:53 AM
sequence of numbers, how to extract which numbers are missing jonlake Programming 13 06-26-2006 04:28 AM
Adding numbers, break on non-numbers... Cruger Programming 1 03-22-2004 10:18 AM


All times are GMT -5. The time now is 10:18 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration