Scyphus Draft — Changing login name and file owner

You may want to change your login name or uid without clean installation. This page provides the tips to change login name and/or uid including post-process, such as changing file owner.

Search from this site:
Custom Search

Changing login name and file owner

Changing login name

If you want to change your login name, you can do it by updating the file /etc/passwd. However, this file must be treated carefully, meaning that it must be locked before editing it, and unlocked after editing it. The command vipw(8) enables you to do it by priviledged user (i.e., root) as follows.

# vipw

Note that you can also use chsh(1) command to edit user's information, but the editable information may be limitted compared to vipw(8) command.

If you find a line of the login name that you would like to change, please edit the name. Here, assuming that you want to change the login name user1 to another name user2. If the line of the name corresponds to

user1:*:1001:100::0:0:User1:/home/user1:/usr/bin/bash

please edit this line as follows.

user2:*:1001:100::0:0:User2:/home/user1:/usr/bin/bash

Changing home directory

You can also change the home directory, represented as /home/user1 above, by moving the directory to an appropriate path at the same time. If you edit the file as follows,

user2:*:1001:100::0:0:User2:/home/user2:/usr/bin/bash

you should move the home directory from /home/user1 to /home/user2 by executing the following command.

# mv /home/user1 /home/user2

Changing uid

One of the most difficult tasks related to user account information modification is to change uid of a certain user account. This is because the uid is probably assigned to many files. If you want to change the user1's uid 1001 described above to 1234, you can edit the file /etc/passwd via vipw(8) command as follows:

user1:*:1234:100::0:0:User1:/home/user1:/usr/bin/bash

After editing the file, make sure to change uid of all files owned by the uid 1001 by executing the following command:

# find / -xdev -user 1001 -exec chown -h user1 {} \;

Note that the options of find, -xdev and -user, represent "excluding special device files" and "specifying uid to search", respectively.