- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: copying a group of users to another system
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 06:06 AM
10-28-2008 06:06 AM
I recently added a new group that contains 30 users to one of our 11.11 servers and now need to find a way to copy those users and group onto two other 11.11 systems. They are non trusted. NFS, NIS, LDAP is not available.
There are already other users on these systems so doing a straight copy of /etc/passwd, /etc/group, and /home is not an option.
What is the best way of copying these users without having to manually create them on each system? I do not have scripting experience but is there a way to copy over the passwd file and run a script to add users that are not in the file?
Please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 06:16 AM
10-28-2008 06:16 AM
Re: copying a group of users to another system
for USER in `cat userlist`
do
useradd -u uid -s shell $USER
done
From the man page:
The useradd command creates a user login on the system by adding the appropriate entry to the /etc/passwd file and any security files, modifying the /etc/group file as necessary, creating a home directory, and copying the appropriate default files into the home directory depending on the command line options. The new login remains locked until the passwd (see passwd(1)) command is invoked.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 06:23 AM
10-28-2008 06:23 AM
Re: copying a group of users to another system
> There are already other users on these systems so doing a straight copy of /etc/passwd, /etc/group, and /home is not an option.
Rarely would you ever copy, at-large, the 'passwd' and 'group' files from one server to another.
> What is the best way of copying these users without having to manually create them on each system?
*if* the users on the "source" system are unique and their 'uid's are not already used on the target server, you could (carefully)paste the appropriate records into the target server's 'passwd' file and copy the '/home' directory and files from one server to the ohter. Otherwise:
Script your needs. You could write a script to compose 'useradd' statements that would be run on the "target" server using the contents of the '/etc/passwd' file on the "source" server.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 07:04 AM
10-28-2008 07:04 AM
Re: copying a group of users to another system
Pete - so for example I rcp /etc/passwd to the new server and name it /tmp/passwd1. In your script would I replace `cat userlist` with `cat /tmp/passwd1`? And by doing this would it create the new /home directories?
I really have no practical scripting experience yet, I'm working on learning 2-3 line scripts right now.
Thanks for your replies so far.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 07:12 AM
10-28-2008 07:12 AM
Re: copying a group of users to another system
If the UID and GID values are unique, you can paste the requistive records from on 'passwd' file into another. I would use 'vipw' instead of 'vi' to perform the operation, since 'vipw' adds some locking of the password file that keeps you from clobbering someone else and vice versa.
Unless you have added a new group, there should be nothing to worry about in '/etc/group'.
Pete's suggestion is certainly another valid approach. It will create new home directories and populate them with the standard login profiles, too. Otherwise, copy the home directories from your "source server to your "target" as I suggested.
Another approach would be to hand-code 'useradd' statements into a "script" that simply runs a series of 'useradd' commands with the appropriate arguments.
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 07:46 AM
10-28-2008 07:46 AM
Re: copying a group of users to another system
> so for example I rcp /etc/passwd to the new server and name it /tmp/passwd1. In your script would I replace `cat userlist` with `cat /tmp/passwd1`?
Sort of. I would use something like this to just get the username:
cat /tmp/passwd | awk -F: '{ print $1 }'
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 10:32 AM
10-28-2008 10:32 AM
Re: copying a group of users to another system
I still have not been able to get a working script yet that would do the copies for me.
What I have set up for this group (and need to replicate) is as follows:
All user profiles in the group begin with BP and have UID 3001 and up. The group profile is G3SUP with GID 3000.
My admin experience is also limited. So in Pete's script where is $USER defined? If for example I have a copy of /etc/passwd on the sysa called /tmp/passwd what would my script look like to get those users onto syslab?
Thank you for the responses so far.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 08:23 PM
10-28-2008 08:23 PM
SolutionIf you don't care about home directories, or they already exist you can do something like the following:
grep ^BP /tmp/passwd > passwd.BP
Then use vipw to edit /etc/passwd and in vi, you go to the last line and do:
:r passwd.BP
:wq
This will copy all new users that start with "BP" to the end of the passwd file.
(Note: If using NIS, make sure you add before the last line of "+::-2:-2:::".)
If you want to use useradd(1m) to create the home directories, you could use some of the scripts on these threads:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=482647
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1249875
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1245220
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1217047
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=437648
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=619269
One thread talks about using /usr/sam/lbin/useradd.sam to add the password. I suppose you could try that, or you could use useradd, then remove those new entries and use the vipw solution to copy the entries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-28-2008 08:31 PM
10-28-2008 08:31 PM
Re: copying a group of users to another system
for USER in $(< userlist); do
useradd -u uid -s shell $USER
done
Basically the file userlist contains a list of users to add. Unfortunately every $USER has the same uid and shell.
If you want to take it from your /tmp/passwd, you could use Pete's second suggestion:
for USER in $(awk -F: '{ print $1 }' /tmp/passwd); do
useradd -u uid -s shell $USER
done
Unfortunately this still has the problem of not using the UID and other info from the old passwd file. That's why you should look at the other threads I mention above where others have asked the same questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2008 08:33 AM
10-29-2008 08:33 AM
Re: copying a group of users to another system
What I ultimately did on my lab system to test things out:
/cat /tmp/passwd | grep ^BP > /tmp/BPusers
then I ran the script from this thread:
http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1217047&admit=109447626+1225297837768+28353475
The only thing I'd have to adjust would be password aging but I might be able to add it into the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-29-2008 08:35 AM
10-29-2008 08:35 AM