Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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)

share|improve this question
    
/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. –  maxmackie 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! –  Bruce Ediger Jan 10 '12 at 14:28

3 Answers 3

up vote 5 down vote accepted

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.

share|improve this answer
    
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
    
find -xdev restricts itself to a single filesystem. You might need to run it once for each filesystem of interest. –  Keith Thompson 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).

share|improve this answer
1  
killing all processes owned by a user is a lot simpler using pkill -U, instead of a manual ps | grep method. –  Patrick 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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