Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
little "rename user" script.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
wizy
Tux's lil' helper
Tux's lil' helper


Joined: 26 May 2002
Posts: 133

PostPosted: Tue Jun 18, 2002 6:04 pm    Post subject: little "rename user" script. Reply with quote

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
View user's profile Send private message
DArtagnan
l33t
l33t


Joined: 30 Apr 2002
Posts: 942
Location: Israel, Jerusalem

PostPosted: Tue Jun 18, 2002 7:46 pm    Post subject: Reply with quote

Nice :-)
We have a "Tips" forum ...post there
_________________
All for one and one for All
--

MACPRO machine...
Back to top
View user's profile Send private message
wizy
Tux's lil' helper
Tux's lil' helper


Joined: 26 May 2002
Posts: 133

PostPosted: Tue Jun 18, 2002 8:05 pm    Post subject: Yeah Reply with quote

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
View user's profile Send private message
Zu`
l33t
l33t


Joined: 26 May 2002
Posts: 716
Location: BE

PostPosted: Tue Jun 18, 2002 11:52 pm    Post subject: Reply with quote

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 :roll:
Back to top
View user's profile Send private message
wizy
Tux's lil' helper
Tux's lil' helper


Joined: 26 May 2002
Posts: 133

PostPosted: Wed Jun 19, 2002 2:40 pm    Post subject: Easy Reply with quote

The old user is actually renamed, the password stays the same.
Back to top
View user's profile Send private message
CptFastbreak
n00b
n00b


Joined: 04 Sep 2007
Posts: 16

PostPosted: Tue Sep 04, 2007 4:01 pm    Post subject: Reply with quote

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
Code:
groupmod -n $2 $1

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum