I connect with ssh to an Ubuntu server to edit some files in /var/www witch I have set the setgid bit:

# sudo chgrp -R www-data /var/www
# sudo chmod -R 770 /var/www
# sudo chmod -R g+s /var/www

I have added the user "user" to www-data group. Now I connect using ssh as user "user" to my server with nautilus. When I copy files using nautilus file get the group permission 'www-data' as they should.

But if I edit a file using Gedit and save it, the file's group get changed to "user" group ?!?

How is this possible? Shouldn't setgid bit avoid this?