View previous topic :: View next topic |
Author |
Message |
wizy Tux's lil' helper
Joined: 26 May 2002 Posts: 133
|
Posted: Tue Jun 18, 2002 6:04 pm Post subject: little "rename user" script. |
|
|
Wrote this for my computer up at work. Just makes it easier to rename a user and save the contents of their old directory to their new directory.
Usage is very simple: chuser OLD_USER NEW_USER
Code: |
# chuser script, by gregg.
# Thanks to my friend myriad for the idea.
# 6/18/2002 - written on my gentoo box at work.
if [ "$1" = "" -o "$1" = "--help" -o "$2" = "" ]; then
echo "Usage: chuser OLD_USER NEW_USER"
exit -1
else
if [ "$1" != "$2" ]; then
echo "Old user: $1"
echo "New user: $2"
echo "Changing home directory"
echo "Changing login"
usermod -d /home/$2 -l $2 $1
echo "Moving and chowning old directories content."
mv /home/$1 /home/$2 && chown -R $2.users /home/$2
exit 0
else
echo "Old user and new user are the same. Nothing to do."
exit -1
fi
fi
|
There you go, hope someone finds this usefull. I know its simple, but always helpfull to make things even easier. |
|
Back to top |
|
|
DArtagnan l33t
Joined: 30 Apr 2002 Posts: 942 Location: Israel, Jerusalem
|
Posted: Tue Jun 18, 2002 7:46 pm Post subject: |
|
|
Nice
We have a "Tips" forum ...post there _________________ All for one and one for All
--
MACPRO machine... |
|
Back to top |
|
|
wizy Tux's lil' helper
Joined: 26 May 2002 Posts: 133
|
Posted: Tue Jun 18, 2002 8:05 pm Post subject: Yeah |
|
|
I saw that area, but it said for speed ups, and preformance tips. I figured this was neither. Maybe the description could be changed? |
|
Back to top |
|
|
Zu` l33t
Joined: 26 May 2002 Posts: 716 Location: BE
|
Posted: Tue Jun 18, 2002 11:52 pm Post subject: |
|
|
That's a nice script, but what happens with the passwords? And also, is the old user removed?
Or perhaps I *should* read man usermod |
|
Back to top |
|
|
wizy Tux's lil' helper
Joined: 26 May 2002 Posts: 133
|
Posted: Wed Jun 19, 2002 2:40 pm Post subject: Easy |
|
|
The old user is actually renamed, the password stays the same. |
|
Back to top |
|
|
CptFastbreak n00b
Joined: 04 Sep 2007 Posts: 16
|
Posted: Tue Sep 04, 2007 4:01 pm Post subject: |
|
|
Last reply to this thread was about 5 years ago, still, I found it via Google and have but one remark on the script, in case someone else stumbles upon it:
You can save the copying over and chowning of the user data if you use the -m switch on usermod (cf. man usermod):
Code: | usermod -d /home/$2 -m -l $2 $1 |
It's also safer, since afaik recently the home directory is not group-owned by users, but by a group with the same name as the user. In that case you should also do
Also, the chown is not really needed even if you do copy the files directly, since the uids remain the same, just the user entries in /etc/passwd and /etc/shadow are changed. So all files previously owned by user $1 will then be owned by $2. |
|
Back to top |
|
|
|