Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux ssh转换为本地主机根权限_Linux_Ant_Ssh_Permissions_Sudo - Fatal编程技术网

Linux ssh转换为本地主机根权限

Linux ssh转换为本地主机根权限,linux,ant,ssh,permissions,sudo,Linux,Ant,Ssh,Permissions,Sudo,我正在从事一个项目,其中代码最初用于ssh到其他4台远程计算机上运行测试。由于计算能力的提高,我的任务是在一台计算机上运行它们 通常情况下,该程序ssh到root@computer1,进行一些复制和粘贴 ant文件中的示例代码之一是: <target name="overwrite-config-file"> <exec executable="bash" inputstring="echo '${database.password}' | sudo -S rm -rf

我正在从事一个项目,其中代码最初用于ssh到其他4台远程计算机上运行测试。由于计算能力的提高,我的任务是在一台计算机上运行它们

通常情况下,该程序ssh到root@computer1,进行一些复制和粘贴

ant文件中的示例代码之一是:

<target name="overwrite-config-file">
    <exec executable="bash" inputstring="echo '${database.password}' | sudo -S rm -rf ${config.file}" />
    <exec executable="bash" inputstring="echo '${database.password}' | sudo -S cat ${new.config.file} > ${config.file}" />
</target>

在其他计算机上使用root时,一切正常

现在我在一台计算机上尝试这个,我通过创建4个帐户来“模拟”计算机,我将ssh转换为computer1@localhost等等

问题在于root@computer1所有的复制和粘贴工作都很好,但是使用ssh到localhost,我没有root的管理权限,每次我尝试对文件执行任何操作时,它都会响应“权限被拒绝”,正如您可以看到的,我在这些命令中有sudo,但仍然会出现“权限被拒绝”错误


tl;dr:是否要授予用户root权限以便权限不会被拒绝?

您是否排除了本地主机上${database.password}为空的可能性?这就解释了“拒绝许可”的原因。并不是说作为root运行的东西通常需要sudo活动来开始。我想你没有分享大局的一部分:}@tink不幸的是,我有,我在exec之前添加了一个echo,它能够给出正确的密码,我注意到第一行有效,第二行无效。从我目前对它的研究来看,这似乎是因为“>”的缘故,但我还不知道如何替换它。那么,一旦启动脚本,它是否会切换到其他用户?可以很容易地在${config.file}前面加上~/使其成为~/${config.file}(假设其他用户有家)。这一切都是以root用户身份运行的,我假设,出于某种原因,文件系统是只读的。@tink${config.file}指向/etc/filename.txt,这就是为什么在试图以root用户身份对/etc文件夹中的文件进行cat时,权限被拒绝的原因computer1@localhostCan你试试这个?sudo-S sh-c“cat${new.config.file}>${config.file}”?我不知道什么程序正在“执行”我认为是XML文件的内容,也不知道它将如何响应额外的引号;这只不过是暗中捅一刀,极有可能失败。