In a follow up to this question about changing the UID of a user, it is recommended to change the ownership of all files on the system (this answer)

find / -uid 1000 -exec chown 5000 '{}' \+

where 1000 is the old UID and 5000 is the new one. I just listed all files (outside /home/seb) owned by UID=1000 and found that most are in the /proc directory.

find / -uid 1000 \! -wholename '/home/seb/*'

Is it save or necessary to perform the suggested UID change? I'm not familiar with the purpose of these /proc files, but I assume they would be created as needed when I log in with the new user.

Note: There are also some files in /dev owned by UID=1000, but those are just the terminals open by the user (e.g. /dev/pts/23)

  • /proc is a virtual filesystem used for processes (remember UNIX philosophy is that everything "is a file"). Therefore things that would usually work on normal files won't work here.
    – n0pe
    Jan 10 '12 at 14:25
  • Great question! I never would have thought to even ask, and I can't imagine why you'd want to do this, but that's what makes it a great question! Jan 10 '12 at 14:28

I'm assuming the files in /proc that youre saying are owned by UID=1000 the the ones like /proc/12345 (just number directories)? These are process accounting directories, the UID is set to that of the user running the program associated with that directory. If you launch a program with pid '12345' then /proc/12345 will be owned by your user.

I doubt a chown on anything in proc will even work as /proc is not a real file system, its a pseudo-filesystem.

The same goes with /dev, the TTYs are owned by the user that is currently using them.

  • excellent info about /proc. I didn't realize these were process IDs. So that means it is pointless to change the uid.
    – Sebastian
    Jan 10 '12 at 15:02
  • 1
    find -xdev restricts itself to a single filesystem. You might need to run it once for each filesystem of interest. Jan 11 '12 at 1:21

Rather then changing the UID, numbered directories represent open handles to processes. You could either kill all the processes owned by UID=1000 (using ps) or you can close all of its handles (using lsof).

  • 1
    killing all processes owned by a user is a lot simpler using pkill -U, instead of a manual ps | grep method.
    – phemmer
    Jan 10 '12 at 16:14

It is neither possible nor necessary to change the ownership of files under /proc. These files are not stored on a disk, they are generated by the kernel on the fly when you read them. The only ones that don't belong to root are files that provide information about a running process; these belong to the user who is running the process.

Before or after you've changed the ownership of the disk files, kill all the processes running as the former uid. (You can't (sensibly) change the uid of a running process.)

If there are terminals (/dev/tty* or /dev/pts/*) belonging to the user, you should change their uid. In all likelyhood there won't be many left after you kill the user's processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.