How are file permissions handled on external media and other computers?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How are file permissions handled on external media and other computers?
I was wondering, what if you had a flash drive formatted with an FS that has UNIX permissions. Then what if you copied some of your files onto it. And then put it into another computer that has a user account by the same name. WIll the user be able to access the files?
What if you named your own user differently on the other computer, will you be able to get your files?
Distribution: Debian 5 - Slackware 13.1 - Arch - Some others linuxes/*BSDs through KVM and Xen
Posts: 329
Rep:
AFAIK, it's not the username that is important, it's the user ID.
So, if your hypotetic user has the same UID in both systems (not necessarily the same username), then yes, (s)he will be able to access those files as well.
It is the UID of the files that determined ownership. Yes, another computer with a user of that UID will have access to the filesystem.
On that computer "ls -l" will list the username that corresponds to the same UID. The filesystem doesn't contain usernames. The kernel doesn't use usernames either.
The filesystem itself will have user.group permissions. When mounted, the user & group of the mountpoint will change to reflect those of the filesystem. To access the filesystem, a user has to have the right permissions. The root user on that computer could use chmod and chown of course.
If you want the contents to be private, you will need to use an encrypted filesystem. E.G. use cryptsetup to create an encrypted partition before formatting it.
I still don't quite understand. So I have Linux installed on my computer. I save my stuff to a flash drive. I reinstall Linux on the computer. My new accound has a different UID. Will I have access to my files?
EDIT: And if my new installation has another user with the same UID as my account on the original installation, will the new installation show the wrong username?
The new distribution will show the wrong username (if the drive is not somehow encripted with a password or the other), but the file will be definitely accessible to other users according to the permissions set for other users:
So:
ls -laR "files on the drive" # and check for the string with 3-4 numeric characters which represent the user permissions (for more details type in "man chmod", man is a manual).
The new distribution will show the wrong username (if the drive is not somehow encripted with a password or the other), but the file will be definitely accessible to other users according to the permissions set for other users:
So:
ls -laR "files on the drive" # and check for the string with 3-4 numeric characters which represent the user permissions (for more details type in "man chmod", man is a manual).
So i'd have to recursively chown the drive to restore ownership to me, right?
And is it right that before I chown it, the files will belong to the other user?
I'd rather chmod or umask recursively if I'd want the files to be read by someone else. In other case, I mean if I would want the files to be read only to me and not anyone else, I'd use some crypting for the drive (but be careful about the password). Anyway a recursive chown for your files is a good way for reclaiming ownership
What if I had a tar file that was made on my theoretical previous Linux installation, and I extract it on the new one? Will its contents belong to the other user on the new installation, or the user that extracted it?
So i'd have to recursively chown the drive to restore ownership to me, right?
And is it right that before I chown it, the files will belong to the other user?
To the first question: Not necessarily. As someone mentioned above, the file/directory permissions are set by UID. This doesn't depend on the installation. The following is hypothetical, I didn't test it. Let's assume that in an original installation, let's say Ubuntu, your user ID is 1001. Next you install Debian and you set up a user with ID 1001. The content previously belonging to the Ubuntu user with UID 1001 now belongs to to the Debian user with UID 1001. Note that the Debian install would not have to replace the Ubuntu install (e.g., multi-boot).
To find out what your UID is, just type the command id at the prompt. I believe the value is kept in /etc/group.
To the second question, yes, the file and directory permissions always belong to the original user until reset by chown.
Quote:
Originally Posted by MTK358
What if I had a tar file that was made on my theoretical previous Linux installation, and I extract it on the new one? Will its contents belong to the other user on the new installation, or the user that extracted it?
tar preserves permissions, using UID. So when you extract the tarball, the uid of the extracted directories and files are set as they were recorded. This has to make sense on the new system; if for example you extracted content with uid 1003 on a system without that had no user with uid 1003, then listing the content would show 1003 instead of a username.
This is useful when reinstalling a system when, for example, your /home directory is on its own partition. See the fourth post of this thread for a way to get the users set up in the new system with all their home content ready; it creates the user using the pre-existing uid.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.