Does file user ownership change when transferring files between computers?

bretonics

Scenario: A file created under computer A (userA), which takes file ownership as userA in file permissions, is then transferred to computer B with a different user (userB)....

Does the ownership of the original file change from the original user (userA) in computer A to the user (userB) of computer B?

How can I create a file that is only writable by me, the creator and owner, and only readable to anyone who might receive that file on other computers?

I created a testfile.txt with file permissions 755 on computer A (userA) to compare the permissions and ownerships of this file before and after I transferred it using scp from computer A to B. I noticed how my original file, now on computer B, has the user id as userB instead of userA [where the file was created].

Computer A, having 'userA'

rwx-r-x-r-- userA testfile.txt

Computer B, having 'userB'

rwx-r-x-r-- userB testfile.txt

I thought, and wanted, to make the file only readable, writeable, and executable by the owner (which I thought would be the user from the computer I created the file in).

Thanks! I am new at this!

Rich

Yes.

This all depends on who creates the file on the destination. Try this:

$ touch some_file
$ ls -l some_file
-rw-r--r-- 1 userA userA 0 Apr 9 17:44 some_file
$ ls -ln some_file
-rw-r--r-- 1 501 501 0 Apr 9 17:44 some_file

So in my example, userA's numeric uid is 501.

Now transfer it, logging into the remote system as userB:

$ scp some_file userB@computerB:
$ ssh userB@computerB ls -l some_file
-rw-r--r-- 1 userB users 0 Apr 9 17:50 some_file
$ ssh userB@computerB ls -l some_file
-rw-r--r-- 1 1743 20 0 Apr 9 17:50 some_file

As you see here, userB created the file, and userB has numeric uid 1743. See also how the timestamp changed?

This is the default behavior of scp. You can preserve attributes though by using scp's "-p" option. This only preserves timestamp and permissions -- and importantly, not ownership. This might be exactly what you're looking for:

$ scp -p some_file userB@computerB:
$ ssh userB@computerB ls -l some_file
-rw-r--r-- 1 userB users 0 Apr 9 17:44 some_file
$ ssh userB@computerB ls -l some_file
-rw-r--r-- 1 1743 20 0 Apr 9 17:44 some_file

Note that besides scp, there are many different ways of creating files on remote machines -- NFS, FTP, WebDAV... these will behave in different, but similarly predictable ways. Let's not get carried away though -- you asked about scp.

(OT note, you actually created the file with 754 permissions! rwx=111=7, r-x=101=5, r--=100=4 – you see, r, w and x are bits in an octal word where r=4, w=2, x=1. That's why you'll see references to octal in relation to permissions. Thanks ernie for the correction!)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Change permissions of file when group has ownership, but user does not

From Dev

How to change file ownership when chown says "invalid user: ‘–R'"?

From Dev

Windows file permissions/ownership are preventing me syncing between computers

From Dev

why does Intellij change the ownership of files to root?

From Dev

Change linux user default ownership on file creation?

From Dev

Change linux user default ownership on file creation?

From Dev

Most efficient process for transferring ownership of all of a user's files using the Google Drive API

From Dev

How to grant a user rights to change ownership of files/directories in a directory

From Dev

unable to change ownership of files

From Dev

unable to change ownership of files

From Dev

Slow speed when transferring files between android phone and computer

From Dev

Why unprivileged user can't change file ownership?

From Dev

How come I, as a normal user, am able to change ownership of a file?

From Dev

File ownership of created files

From Dev

Move files and change ownership at the sametime

From Dev

Change ownership of a large group of files

From Dev

Change ownership of file from a user to another user which the first user controlls

From Dev

Does computers on same LAN share their hosts file between each others?

From Dev

Does windows change files when file extensions are changed?

From Dev

Transferring ownership to a manager

From Dev

List File Space Ownership By User

From Dev

changing ownership of file as group user

From Dev

Revoke file ownership and give user

From Dev

Is there an R function to change file ownership?

From Dev

Problem with recursive change of file ownership

From Dev

How and when does `exec` change the effective user ID, when the set-user-ID is set for the executable file

From Dev

Transferring dates between Excel files (inaccurately)

From Dev

Changing group ownership of files - User management

From Dev

Change Folder Ownership From Root To User

Related Related

  1. 1

    Change permissions of file when group has ownership, but user does not

  2. 2

    How to change file ownership when chown says "invalid user: ‘–R'"?

  3. 3

    Windows file permissions/ownership are preventing me syncing between computers

  4. 4

    why does Intellij change the ownership of files to root?

  5. 5

    Change linux user default ownership on file creation?

  6. 6

    Change linux user default ownership on file creation?

  7. 7

    Most efficient process for transferring ownership of all of a user's files using the Google Drive API

  8. 8

    How to grant a user rights to change ownership of files/directories in a directory

  9. 9

    unable to change ownership of files

  10. 10

    unable to change ownership of files

  11. 11

    Slow speed when transferring files between android phone and computer

  12. 12

    Why unprivileged user can't change file ownership?

  13. 13

    How come I, as a normal user, am able to change ownership of a file?

  14. 14

    File ownership of created files

  15. 15

    Move files and change ownership at the sametime

  16. 16

    Change ownership of a large group of files

  17. 17

    Change ownership of file from a user to another user which the first user controlls

  18. 18

    Does computers on same LAN share their hosts file between each others?

  19. 19

    Does windows change files when file extensions are changed?

  20. 20

    Transferring ownership to a manager

  21. 21

    List File Space Ownership By User

  22. 22

    changing ownership of file as group user

  23. 23

    Revoke file ownership and give user

  24. 24

    Is there an R function to change file ownership?

  25. 25

    Problem with recursive change of file ownership

  26. 26

    How and when does `exec` change the effective user ID, when the set-user-ID is set for the executable file

  27. 27

    Transferring dates between Excel files (inaccurately)

  28. 28

    Changing group ownership of files - User management

  29. 29

    Change Folder Ownership From Root To User

HotTag

Archive