简体   繁体   中英

Linux: How can I SSH connect using Apache user?

As a web developer I always have the problem when updating PHP (and other) files from an SSH client, because I am logged in as a user or simply root. After that update I always have to run manually from a terminal 'chown -R apache:apache *' to make the files accessible.

I tried to make a user ID and add it to the group 'apache' and add the apache user to the group of my user id. That works only for existing files on the server file system, because newly created files have permissions rwxr--r-- which does not allow writing by my user even as it is in the 'apache' group.

I'd like to make a login (shell is not needed) for the Apache user, so I can use an SSH based file browser like Forklift to login as Apache or use sshfs to mount as Apache user.

Another way is make umask that my user id always sets attributes of newly created files from sshfs mount or a file browser (mounted with my user id, not root) that they have permission rwxrwxr-- (ie 0775) by default.

Is there a way I can upload files to the server (updating existing op create new ones) without having to worry about permissions by Apache?

You have to set the setgid

For example, do the following steps:

adduser hugo
addgroup apache
usermod -a -G apache hugo

mkdir /tmp/example
chown hugo:apache /tmp/example
chmod g+s /tmp/example

su hugo
cd /tmp/example
touch my_file
ls -l

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM