简体   繁体   English

Linux:如何使用 Apache 用户连接 SSH?

[英]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.作为 web 开发人员,从 SSH 客户端更新 PHP(和其他)文件时,我总是遇到问题,因为我是以用户身份登录或只是 root。 After that update I always have to run manually from a terminal 'chown -R apache:apache *' to make the files accessible.在该更新之后,我总是必须从终端“chown -R apache:apache *”手动运行以使文件可访问。

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.我尝试创建一个用户 ID 并将其添加到“apache”组中,并将 apache 用户添加到我的用户 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.这仅适用于服务器文件系统上的现有文件,因为新创建的文件具有权限 rwxr--r-- 不允许我的用户写入,即使它在“apache”组中也是如此。

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.我想为 Apache 用户登录(不需要 shell),因此我可以使用基于 SSH 的文件浏览器(如 Forklift)以 Apache 登录或使用 sshfs 挂载为 Apache 用户。

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.另一种方法是设置 umask,我的用户 ID 总是从 sshfs 挂载或文件浏览器(使用我的用户 ID,而不是 root 挂载)设置新创建的文件的属性,默认情况下它们具有权限 rwxrwxr--(即 0775)。

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?有没有一种方法可以将文件上传到服务器(更新现有操作创建新操作)而不必担心 Apache 的权限?

You have to set the setgid你必须设置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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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