Friday, September 9, 2011

Change UserID (uid) and GroupID (gid) in Linux

In case, required to change certain user uid and gid in Linux. We can editing the /etc/passwd will be sufficient. But going to face some serious issue on the file permission which been associate with the user.

For example, changing the uid and gid for mysql user daemon. May face MySQL directory not working or cant start the mysql services. Same applied to apache or whatever services daemon.

So, here the step can use to solve all the headache.
Existing zabbix user uid and gid from /etc/passwd
zabbix:x:1008:1008::/home/zabbix:/bin/bash

New uid and gid for zabbix is 300:300

1. Change the uid and gid:
groupmod -g 300 zabbix
usermod -u 300 -g 300 zabbix

2. Find all directory and change to new uid and gid:
find / -user 1008 -print0 | xargs -0 chown -h 300
find / -group 1008 -print0 | xargs -0 chgrp -h 300

That all.. job done.



No comments: