niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » *nix » Linux » security
How to create /etc/passwd file?
Post new topic   Reply to topic Page 1 of 2 [23 Posts] View previous topic :: View next topic
Goto page:  1, 2 Next
Author Message
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Sun Jun 25, 2006 10:48 am    Post subject: Re: How to create /etc/passwd file? Reply with quote

floyd@apaflo.com (Floyd L. Davidson) (06-06-25 01:53:33):

Quote:
Even easier:

tr -d "\r" < SRCFILE > DESTFILE

col -xb < SRCFILE > DESTFILE

Hmmm... that looks to be 3 characters shorter! :-)

I don't /tr/ as being easier, plus it is not as functional.

/tr/ only translates exactly what you tell it to, while /col/ was
specifically designed to remove unknown control sequences. For
example, with the -b option it removes all but that last of any series
of "<BS>c", where c is any character, and with -x it will replace tabs
with spaces. There is no way to get /tr/ to do those too, plus remove
any other non-effective carriage control sequences.

Well, 'col' is more intelligent than 'tr', and processes its input. In
some situations, you don't want that, and instead just remove (or
translate) a selected set of characters. 'tr' is better in that case.


Regards,
E.S.
Back to top
Floyd Davidson
*nix forums Guru Wannabe


Joined: 02 Nov 2005
Posts: 124

PostPosted: Sun Jun 25, 2006 9:53 am    Post subject: Re: How to create /etc/passwd file? Reply with quote

Ertugrul Soeylemez <never@drwxr-xr-x.org> wrote:
Quote:
floyd@apaflo.com (Floyd L. Davidson) (06-06-24 09:04:21):

Finally someone with the reasonable answer. If he's working from a
text file with "^M" imbedded, he could A) vi the file and perform a
global search and replace, or B) pipe the output to sed using
'/s[CTRL][v][CTRL][M]//g' to remove the "^M" before using the useradd
command.

That is exactly what /col/ was designed to do. Pipe the file
through /col/, using -x and perhaps -b options.

Even easier:

tr -d "\r" < SRCFILE > DESTFILE

col -xb < SRCFILE > DESTFILE

Hmmm... that looks to be 3 characters shorter! :-)

I don't /tr/ as being easier, plus it is not as functional.

/tr/ only translates exactly what you tell it to, while /col/
was specifically designed to remove unknown control sequences.
For example, with the -b option it removes all but that last of
any series of "<BS>c", where c is any character, and with -x it
will replace tabs with spaces. There is no way to get /tr/ to
do those too, plus remove any other non-effective carriage
control sequences.

--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@apaflo.com
Back to top
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Sun Jun 25, 2006 7:36 am    Post subject: Re: How to create /etc/passwd file? Reply with quote

floyd@apaflo.com (Floyd L. Davidson) (06-06-24 09:04:21):

Quote:
Finally someone with the reasonable answer. If he's working from a
text file with "^M" imbedded, he could A) vi the file and perform a
global search and replace, or B) pipe the output to sed using
'/s[CTRL][v][CTRL][M]//g' to remove the "^M" before using the useradd
command.

That is exactly what /col/ was designed to do. Pipe the file
through /col/, using -x and perhaps -b options.

Even easier:

tr -d "\r" < SRCFILE > DESTFILE


Regards.
Back to top
Floyd Davidson
*nix forums Guru Wannabe


Joined: 02 Nov 2005
Posts: 124

PostPosted: Sat Jun 24, 2006 5:04 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

"KernelPanic" <myngreader@verizon.net> wrote:
Quote:
Finally someone with the reasonable answer. If he's working from a text
file with "^M" imbedded, he could A) vi the file and perform a global search
and replace, or B) pipe the output to sed using '/s[CTRL][v][CTRL][M]//g' to
remove the "^M" before using the useradd command.

That is exactly what /col/ was designed to do. Pipe the file
through /col/, using -x and perhaps -b options.

--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@apaflo.com
Back to top
KernelPanic
*nix forums beginner


Joined: 24 Jun 2006
Posts: 1

PostPosted: Sat Jun 24, 2006 2:01 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

Finally someone with the reasonable answer. If he's working from a text
file with "^M" imbedded, he could A) vi the file and perform a global search
and replace, or B) pipe the output to sed using '/s[CTRL][v][CTRL][M]//g' to
remove the "^M" before using the useradd command.

"Ertugrul Soeylemez" <never@drwxr-xr-x.org> wrote in message
news:e77be1$gmq$03$1@news.t-online.com...
Quote:
Michael Heiming <michael+USENET@www.heiming.de> (06-06-19 23:24:09):

But why the hassle? You can script useradd to do the job more easily
for you. As usual the fine manual 'man useradd' has the info.

Yes, and it's also more portable and optionally allows automatic home
directory creation based on a template, and so on. You shouldn't tamper
with /etc/passwd, /etc/group and /etc/shadow, unless you have a good
reason to do so. Use system tools instead.

To get you started:

for n in `seq 0 8999`; do
useradd -u $((1000 + $n)) -g $((1001 + $n / 1000)) user_$((1000 + $n))
done


Regards,
E.S.
Back to top
Unruh
*nix forums Guru


Joined: 22 Mar 2005
Posts: 1166

PostPosted: Wed Jun 21, 2006 8:32 am    Post subject: Re: How to create /etc/passwd file? Reply with quote

"Ross" <nospam@ross.com> writes:

Quote:
Hi there,
I am going to create 9000 users.
I have all the user names in a txt file userlist.txt like this:
user_1
user_2
:
user_9000


Do your user names actually have the numbers int he names or are there just
9000 different names?

i=1000
for n in `cat nameoffile`
do
echo "$nMad:$i:1000::/home/$n:/bin/bash">>/etc/passwd
i=$(($i+1))
done

Quote:
I want the passwd file to be created like this:
user_1:x:1001:1000::/home/user_1:/bin/bash
user_2:x:1002:1000::/home/user_2:/bin/bash
:
user_1000:x:1001::/home/user_2000:/bin/bash
:
user_9000:x:1009::/home/user_9000:/bin/bash

How could I use bash with something like awk to create the passwd file?
And also the group, shadow files (all passwords can be the same)?
Thanks,
Ross
Back to top
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Tue Jun 20, 2006 10:07 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

Michael Heiming <michael+USENET@www.heiming.de> (06-06-20 02:08:25):

Quote:
There is nothing improper about a Windows text file; the standard
allows CR/LF line endings.

Most programs don't handle them properly. Even some text editors (like
GNU nano) fail there. One reason is that functions like fgets() do
return the CR character as part of the line.


Quote:
Just that it sucks if you edit/transfer text on one and copy to
the other. Strange enough there's zero problem between any kind
of unix system. Just M$ has this problem, perhaps because it
isn't an OS but a fine? Wink

Same with delimiter characters. Where Unix uses ':', Windows uses ';',
and where Unix uses '/', Windows uses '\'. Even basic system functions
names are totally incompatible, like poll() on Unix
vs. MsgWaitForMultipleObjectsEx() on Windows. Microsoft has
sufficiently reached the goal of making Windows programs as unportable
as possible. Wouldn't it be bad, if Photoshop ran equally well on Unix?

Ten screenfuls of source code just to create an empty OpenGL- or
D3D-enabled window via DirectX under Windows. A few more pages of code,
to make it closable. And you couldn't remember all those COM+ calls
needed, without having a browser to MSDN open. You couldn't even
remember their argument list. Even if you do for a single function;
what kind of argument is it? LPARAM, or DOWRD? Or even WINDOWCLASSEX?
Or CREATESTRUCT? Oh, please don't forget, you have to use LPCTSTR
instead of char *.

And (writing this in an own paragraph because of identifier length)
please remember that the FrontEndUploadMemoryUtilizedPercent component
of the D3DDEVINFO_D3D9BANDWIDTHTIMINGS structure is of type FLOAT, not
float!

Same program in Unix via SDL uses just about thirty lines, and can be
done mostly with standard types. Poor Windows coders ...


Regards,
E.S.
Back to top
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Tue Jun 20, 2006 9:20 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

"Chris F.A. Johnson" <cfajohnson@gmail.com> (06-06-20 13:47:12):

Quote:
But why the hassle? You can script useradd to do the job more
easily for you. As usual the fine manual 'man useradd' has the
info.

Yes, and it's also more portable

It is not portable; there are different versions, with different
syntax, even among Linux distros. Other *nixen may not have it at
all.

I didn't say it's portable. I said, it's _more_ portable. Editing
/etc/passwd directly may even be unportable on the same distribution
with a different version.


Regards,
E.S.
Back to top
Michael Heiming
*nix forums Guru


Joined: 19 Feb 2005
Posts: 1423

PostPosted: Tue Jun 20, 2006 8:15 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

In comp.os.linux.networking Ertugrul Soeylemez <never@drwxr-xr-x.org>:
Quote:
Michael Heiming <michael+USENET@www.heiming.de> (06-06-19 23:24:09):

But why the hassle? You can script useradd to do the job more easily
for you. As usual the fine manual 'man useradd' has the info.

Yes, and it's also more portable and optionally allows automatic home

If more portable or not, 'useradd' should ease up things
tremendously.

Basically the versions of useradd on many unix[tm] work the same
as the Linux version, the later has a nice option to hand over a
crypt() string as password. Haven't seen this option in any other
unix[tm], though it might have been added since I checked.

Halfway recent *BSD versions can do the same through 'pw' (iirc).
No rocket science to rewrite with awk one version to another.

Quote:
directory creation based on a template, and so on. You shouldn't tamper
with /etc/passwd, /etc/group and /etc/shadow, unless you have a good
reason to do so. Use system tools instead.

Indeed, strange enough the better idea of doing so occurred me
just after typing the line awk.

Quote:
To get you started:

for n in `seq 0 8999`; do
useradd -u $((1000 + $n)) -g $((1001 + $n / 1000)) user_$((1000 + $n))
done

Nice line of bash. ;-)

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 134: because of network lag due to too many people
playing deathmatch
Back to top
Ross
*nix forums Guru Wannabe


Joined: 26 Mar 2005
Posts: 108

PostPosted: Tue Jun 20, 2006 7:58 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

Thanks a bunch to all guys!
Your replies are very helpful!
Ross

"Ross" <nospam@ross.com> wrote in message
news:UeOdndoExoWHkQrZnZ2dnUVZ_q-dnZ2d@magma.ca...
Quote:
Hi there,
I am going to create 9000 users.
I have all the user names in a txt file userlist.txt like this:
user_1
user_2
:
user_9000

I want the passwd file to be created like this:
user_1:x:1001:1000::/home/user_1:/bin/bash
user_2:x:1002:1000::/home/user_2:/bin/bash
:
user_1000:x:1001::/home/user_2000:/bin/bash
:
user_9000:x:1009::/home/user_9000:/bin/bash

How could I use bash with something like awk to create the passwd file?
And also the group, shadow files (all passwords can be the same)?
Thanks,
Ross
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Tue Jun 20, 2006 5:47 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

On 2006-06-19, Ertugrul Soeylemez wrote:
Quote:
Michael Heiming <michael+USENET@www.heiming.de> (06-06-19 23:24:09):

But why the hassle? You can script useradd to do the job more easily
for you. As usual the fine manual 'man useradd' has the info.

Yes, and it's also more portable

It is not portable; there are different versions, with different
syntax, even among Linux distros. Other *nixen may not have it at
all.


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
Michael Heiming
*nix forums Guru


Joined: 19 Feb 2005
Posts: 1423

PostPosted: Tue Jun 20, 2006 12:08 am    Post subject: Re: How to create /etc/passwd file? Reply with quote

In comp.os.linux.networking Chris F.A. Johnson <cfajohnson@gmail.com>:
Quote:
On 2006-06-19, Michael Heiming wrote:
In comp.os.linux.networking Ross <nospam@ross.com>:

"Bit Twister" <BitTwister@mouse-potato.com> wrote in message
On Mon, 19 Jun 2006 16:42:01 -0400, Ross wrote:
Hi there,
I am going to create 9000 users.
[ short bash script to do it ]

http://tldp.org/LDP/abs/html/index.html

Thanks a lot for your idea!
But the $user comes with new line. The output is like this:
user_1^MMad:1001:1000::/home/user_1^M:/bin/bash
user_2^MMad:1002:1001::/home/user_2^M:/bin/bash
:

How could I eliminate the ^M?

Don't keep your files on a doze box, those can't even handle a
text file probably,

s/probably/properly/

Thx for reminding! ;-)

Quote:
There is nothing improper about a Windows text file; the standard
allows CR/LF line endings.

Just that it sucks if you edit/transfer text on one and copy to
the other. Strange enough there's zero problem between any kind
of unix system. Just M$ has this problem, perhaps because it
isn't an OS but a fine? ;-)

Quote:
as you just encountered. Alternatively run
'dos2unix' over the file.

So much for standards...

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 246: It must have been the lightning storm we had
(yesterday) (last week) (last month)
Back to top
Ertugrul Soeylemez
*nix forums Guru Wannabe


Joined: 28 Oct 2005
Posts: 126

PostPosted: Mon Jun 19, 2006 11:19 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

Michael Heiming <michael+USENET@www.heiming.de> (06-06-19 23:24:09):

Quote:
But why the hassle? You can script useradd to do the job more easily
for you. As usual the fine manual 'man useradd' has the info.

Yes, and it's also more portable and optionally allows automatic home
directory creation based on a template, and so on. You shouldn't tamper
with /etc/passwd, /etc/group and /etc/shadow, unless you have a good
reason to do so. Use system tools instead.

To get you started:

for n in `seq 0 8999`; do
useradd -u $((1000 + $n)) -g $((1001 + $n / 1000)) user_$((1000 + $n))
done


Regards,
E.S.
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Mon Jun 19, 2006 11:05 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

On 2006-06-19, Michael Heiming wrote:
Quote:
In comp.os.linux.networking Ross <nospam@ross.com>:

"Bit Twister" <BitTwister@mouse-potato.com> wrote in message
On Mon, 19 Jun 2006 16:42:01 -0400, Ross wrote:
Hi there,
I am going to create 9000 users.
[ short bash script to do it ]

http://tldp.org/LDP/abs/html/index.html

Thanks a lot for your idea!
But the $user comes with new line. The output is like this:
user_1^MMad:1001:1000::/home/user_1^M:/bin/bash
user_2^MMad:1002:1001::/home/user_2^M:/bin/bash
:

How could I eliminate the ^M?

Don't keep your files on a doze box, those can't even handle a
text file probably,

s/probably/properly/

There is nothing improper about a Windows text file; the standard
allows CR/LF line endings.

Quote:
as you just encountered. Alternatively run
'dos2unix' over the file.


--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
Bit Twister
*nix forums Guru


Joined: 19 Feb 2005
Posts: 1546

PostPosted: Mon Jun 19, 2006 10:22 pm    Post subject: Re: How to create /etc/passwd file? Reply with quote

On Mon, 19 Jun 2006 17:16:37 -0400, Ross wrote:
Quote:

In addition, I'd like to have users grouped like this: gid:1000 for users
user_1 to user_1000, and gid:1001 for users from user_1001 to user_2000,
etc.

Use an if statement around the code bumping the group id to decide
when to bump the group variable.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 2 [23 Posts] Goto page:  1, 2 Next
View previous topic :: View next topic
The time now is Fri Nov 21, 2008 6:32 am | All times are GMT
navigation Forum index » *nix » Linux » security
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Running php file everyday on scheduled time sachin PHP 1 Fri Jul 21, 2006 12:49 pm
No new posts Regarding thesaurus iso file Srikanth modules 0 Fri Jul 21, 2006 10:42 am
No new posts how can i get a file descriptor not used? mars system 0 Fri Jul 21, 2006 7:41 am
No new posts small GTK "Open file" dialog David Siroky Debian 0 Fri Jul 21, 2006 7:30 am
No new posts Trouble Declaring 3D Array in Header File free2klim C++ 1 Fri Jul 21, 2006 4:07 am

Mobile Phone deals | Loans | Credit Cards | Loans | Mortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.4285s ][ Queries: 16 (0.2906s) ][ GZIP on - Debug on ]