3

I'm mounting a remote linux file system on Ubuntu 16.04 using Nautilus by "Connect to server" then

sftp:myusername@myhost/home/myusername/scripts/myfile.ext

The file has ownership myusername:groupA on the remote server.

When I edit and save the file remotely with Gedit or another editor it changes the ownership on the server to myusername:myusername

It doesn't respect the initial group ownership.

Is there a way to change this behaviour?

Edit:

When I right click the file in Nautilus it says the group ID is 115. I looked up the name with..

getent group 115 | cut -d: -f1

and it returns whoopsie.

Which leads me to believe it some sort of error. Maybe Ubuntu doesn't recognize the remote group name?

Edit:

The group name groupA exists on both the local and remote machines but with different group IDs. I wonder if that is the problem.

1
+50

Please take care of the following consideration.

  • Any new file will use the default umask 022
  • Any new file will be owned by the creator user and his primary group.
  • A file modified from SFTP is not modify on the server, but a copy is made in RAM on opening, then the file is overwritten in the save. This is the same than deleting the file then create a new one.

The solution:

There are probably more than one solution, but the easiest way is using ACL. From the server (e.g. by ssh), first check you have the acl command available.

apt install acl

You may have to check that your file system is mounted with ACL (this is the default since a while now). Replace / by the appropriate mount location of your folder.

mount -o remount,acl /

note : you may need to alter your /etc/fstab to make it permanent.

Finally, you have to change the default ACL of the folder where you want to save your file. Note any new file created in this folder will get this new right.

setfacl -d -m g:group:rwx /your/folder

Replace group by the wanted "group" and "/your/folder" by the folder you will store your file. You may also adapt rwx in case of you don't need executable right (in that case, use only rw).

2
  • The fact that sftp has to delete the file and create a new one means it won't have permissions to set the group ID to anything other than the user's primary group or the file permissions with anything other than umask 022? That makes sense to me but I don't see why it would be a problem for sftp to be designed in a way that if you have permission on the file then you should be able to edit while keeping the permissions all the same. That would make more sense to me. CLI editors just became more relevant for me. – deanresin Jan 12 '19 at 1:43
  • It's really depending of the way that client is connecting. But many SFTP client are stupid and just override a file without taking care of any previous right. – ob2 Jan 15 '19 at 8:49

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.