ssh - 由于您的组,如何确定您是否可以使用 SFTP 写入目录?

标签 ssh permissions sftp

报价 How to determine if you can write to a file with SFTP because of your group? ,

You could do mode & 00002 to see if a [directory] is writable by the public and you could get a directory listing to and see if the owner of . matches the user that you logged in with (although stat doesn't usually return the longname for SFTPv3 servers, which is what you'd need to get the username from that) but what about group permissions?



在对该帖子的回答中,建议使用 SFTP 测试文件可写性的更好方法是实际打开该文件进行写入。例如。类似于 fopen('filename.ext', 'w'); 的东西.

我的问题是......确定使用 SFTP 的目录的可写性的最佳方法是什么?您不能像打开文件一样打开目录进行写入。我最好的猜测:只是尝试在有问题的目录中上传一个临时文件?

可能使用 SSH_FXF_CREAT 和 SSH_FXF_EXCL?尽管文件可能已经存在的可能性有点使事情复杂化。我想可以获得一个目录列表,然后可以尝试上传一个不存在的文件名,但是,如果目录超大,这将需要读取权限这一事实也无法正常工作。

有任何想法吗?

最佳答案

一个可以执行 touch 的登录脚本怎么样?在那个用户的那个目录上?

如果 sshd你可以使用 pam_script (执行脚本的 pam auth 模块)只是简单地做一个 touch testing_file_creation在您的目录中。您需要添加到您的 pam sshd 配置中。

如果目录将 不是 可写,您会在登录时收到一条消息touch: testing_file_creation: Permission denied .当然,你可以用它做更多花哨的东西,但这将是非常基本的。

关于ssh - 由于您的组,如何确定您是否可以使用 SFTP 写入目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54985650/

相关文章:

android - 无法拦截在 Marshmallow 中拒绝权限的用户

python - 在 Windows 7 上安装 Python 和分发会得到 "Writing failed ... permission denied"

java - 使用 JSch 执行 SFTP 时无法连接到安全通道

python - 使用 Python Paramiko 将 .csv 文件从 SFTP 服务器读取到内存

php - 在 Mac 上将 openshift mysql 连接到 netbeans

docker - 在没有 "--net host"的情况下,在通过 SSH 连接的服务器上可靠地在 Docker 容器中运行 X 应用程序

linux - 使用 nohup 在与 ssh 断开连接时帮助运行 python 代码循环

security - 创建一个经过身份验证的用户可以访问但匿名用户不能访问的安全 Orchard CMS 页面

php - 用于在一系列文件中进行 grep 的 Shell 脚本

linux - bash变量似乎无法分配给在容器中执行的psql输出