尝试在远程服务器上执行脚本(创建文件夹):“权限被拒绝”[关闭]

问题描述 投票:-1回答:1

我写了一个非常简单的脚本,允许我在远程服务器上创建具有特定权限的目录。

我使用该命令执行远程服务器的脚本:

[email protected] /root/Documents/script

我得到了这个答案:

 bash: /root/Documents/script: Permission denied
 Connection to 192.168.159.133 closed.

我正在使用Fedora 20,服务器在Ubuntu 18.04.1上。

我尝试使用chmod修改脚本文档的权限:

chmod 777 script

起初我尝试使用集成在脚本中的SSL连接来执行脚本(您可以在我的脚本中看到它)。

我尝试阅读几篇文章,但对于大多数答案,我的知识仍然太弱,无法理解一切。

#!/bin/bash

#Connecting to Ubuntu Server
#ssh [email protected]

#specifying the directory where I want to create my two directories
cd /home/stan

#Creating the first directory "PublicFolder" and assigning permissions
mkdir PublicFolder
chmod -R 606 PublicFolder

#Creating the first directory "PrivateFolder" and assigning permissions
PrivateFolder
chmod -R 604 PrivateFolder
linux bash remote-access permission-denied
1个回答
1
投票

我不会评论脚本中的权限设置,即使它们对我来说很奇怪。我不会评论777,因为那已经完成了。

当您获得权限被拒绝时,可能是因为脚本无法执行或者脚本中的某些内容拒绝执行。您的错误消息表明第一个。

首先:你能读懂这个文件吗?试试cat /root/Documents/script。如果您无法阅读,您应该确保可以。这可能意味着你需要将脚本放在别处(不在root的主目录下),因为有很多原因(参见评论Charles Duffy)。

如果您可以阅读该文件,您可以尝试使用bash /root/Documents/script来执行它。如果这样可行,只需chmod a+x文件即可使其可执行。

那么为什么/root/Documents中的脚本?看到脚本的内容,我希望它在/home/stan/scripts下,或类似的东西。通过这种方式,您可以随时更改其权限,阅读它,甚至确保执行它。

© www.soinside.com 2019 - 2024. All rights reserved.