使用 pscp 并获得权限被拒绝

发布于 2024-10-08 09:12:19 字数 329 浏览 0 评论 0原文

我正在使用 pscp 使用以下命令将文件传输到虚拟 ubuntu 服务器:

pscp test.php user@server:/var/www/test.php

并且出现权限被拒绝的错误。如果我尝试转移到文件夹 /home/user/ 我没有任何问题。

我想这与我使用的用户无权访问文件夹 /var/www/ 有关。当我使用 SSH 时,我必须使用 sudo 来访问 /var/www/ 路径 - 我确实这样做了。

是否可以指定 pscp 应“sudo”传输到服务器,以便我可以访问 /var/www/ 路径并实际上能够将文件传输到此文件夹?

I'm using pscp to transfer files to a virtual ubuntu server using this command:

pscp test.php user@server:/var/www/test.php

and I get the error permission denied. If I try to transfer to the folder /home/user/ I have no problems.

I guess this has to do with that the user I'm using doesn't have access to the folder /var/www/. When I use SSH I have to use sudo to get access to the /var/www/ path - and I do.

Is it possible to specify that pscp should "sudo" transfers to the server so I can get access to the /var/www/ path and actually be able to transfer files to this folder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情愿 2024-10-15 09:12:19

如果您拥有服务器:

将自己添加到 www-data 组:

sudo usermod -a -G www-data <username>

并设置正确的权限:

sudo chown -R www-data:www-data /var/www/
sudo chmod -R 0775 /var/www/

这应该可以解决问题。

If you own the server:

Add yourself to the www-data group:

sudo usermod -a -G www-data <username>

And set the right permissions:

sudo chown -R www-data:www-data /var/www/
sudo chmod -R 0775 /var/www/

This should do the trick.

很酷又爱笑 2024-10-15 09:12:19

请注意以下事项,当您编写

sudo usermod -G www-data <username>

选项 -G 时,将使指定的用户 () 成为指定的特定组的成员。因此,上述语句将使用户成为 www-data 组的一部分,但会将用户从该用户所属的任何其他组中删除。为了避免这种情况,您必须添加选项 -a 或指定您希望用户加入的所有当前组。我不小心把用户“administrator”从 sudo 组中删除了,因为我不知道这一点。因此,如果您希望指定的用户保留其当前的组成员身份,请编写以下命令。

sudo usermod -G -a www-data <username>

有关 usermod 命令的更多信息,请访问:

Ubuntu 手册页 - usermod< /a>

Beware of the following that when you write

sudo usermod -G www-data <username>

The option -G will make the specified user () a member of the particular group(s) that are specified. So the above statement will make the user a part of group www-data BUT will remove the user from any other group that the user belongs to. To avoid this you must either add the option -a or specify all the current groups that you want the user to be a part of. I accidently took the user "administrator" out of the sudo group because I didn't know this. So if you want the specified user to keep it's current group membership then write the following command.

sudo usermod -G -a www-data <username>

For more info regarding the usermod command, visit:

Ubuntu manpages - usermod

彼岸花ソ最美的依靠 2024-10-15 09:12:19

我遇到了同样的错误“pscp:无法打开 YourFilePath:权限被拒绝”,

请检查您尝试覆盖的文件的所有权,
如果您无法覆盖它,您将收到此错误。

如果您无法控制远程文件,只需尝试重命名您要移动的文件即可。

I had the same error "pscp: unable to open YourFilePath: permission denied",

check the ownership of the file you are trying to overwrite,
you will get this error if you can't overwrite it,

If you don't have control over the remote file, just simply try to rename the file you are trying to move.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文