bash 使用 SSH 运行 swapon 时找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16912237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Command not found when running swapon with SSH
提问by itzhaki
I'm trying to use "swapon -s" remotely but getting "command not found"
我正在尝试远程使用“swapon -s”但“找不到命令”
$ ssh ns2 swapon -s
bash: swapon: command not found
Using it locally works perfectly, what could be the reason for this?
在本地使用它完美无缺,这可能是什么原因?
采纳答案by Aaron Digulla
There are several possible reasons:
有几个可能的原因:
- You're not root at the remote side. Check this with
who am iorid. To make sure you're root, usessh root@ns2 ... - Your path is wrong. This is often a problem with
sudo. Tryssh ns2 sudo /sbin/swapon
- 您不是远程端的 root。使用
who am i或 进行检查id。要确保您是 root,请使用ssh root@ns2 ... - 你的路径是错误的。这通常是
sudo. 尝试ssh ns2 sudo /sbin/swapon
回答by Denny Crane
Maybe you're not in the sudoers file or you need to enter a password.
也许您不在 sudoers 文件中,或者您需要输入密码。
Be sure that you're really root so try try this and look if it differs:
确保你真的是 root 所以试试这个,看看它是否不同:
ssh server.tld id
ssh server.tld sudo id
The second one should give you an output which should be this:
第二个应该给你一个输出,应该是这样的:
uid=0(root) gid=0(root) groups=0(root)
If this is not the output check your /etc/suders which should have an entry like this:
如果这不是输出,请检查您的 /etc/suders 应该有这样的条目:
foo ALL=NOPASSWD: ALL
The command I runned and which worked:
我运行的命令有效:
ssh -l foo server.tld sudo swapon -s
回答by mirkobrankovic
Try to ran
试着跑
which swapon
If it returns something likeno swapon in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:...)
it means that swapon script isn't found anywhere
如果它返回类似的东西,no swapon in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:...)
则意味着在任何地方都找不到 swapon 脚本

