简体   繁体   English

鱼壳新功能:“ ssh:找不到命令”

[英]Fish shell new function : “ssh: command not found ”

I'm trying to create a function that connects me to a ssh server then become su, and then ssh into another server so I did the following: 我试图创建一个将我连接到ssh服务器,然后变成su,然后再ssh到另一台服务器的函数,所以我执行了以下操作:

function test 
     ssh -t testuser@server1 'sudo ssh -t testuser@server2' 
end

When I execute it I get the following error ssh: command not found 当我执行它时,出现以下错误ssh: command not found

But when I execute it straight to the terminal it works with no problems. 但是,当我直接将其执行到终端时,它没有任何问题。

This sounds like a path issue on server1. 这听起来像server1上的路径问题。

From the command line, what do you see if you type the following? 在命令行中,如果键入以下内容,您会看到什么?

ssh -t testuser@server1 sudo which ssh 

If SSH is not in the path for root, you might need to specify full paths, such as something like: 如果SSH不在root路径中,则可能需要指定完整路径,例如:

ssh -t testuser@server1 sudo /usr/bin/ssh testuser@server2

You may need to adjust the paths to match your environment, of course. 当然,您可能需要调整路径以匹配您的环境。

Also, if you're trying to connect from root at server1 to server2, can you just ssh directly to root@server1? 另外,如果您尝试从server1的根目录连接到server2,是否可以直接将ssh直接连接到root @ server1? If so, you could perhaps use the "ProxyJump" functionality that was added with OpenSSH 7.3. 如果是这样,您也许可以使用OpenSSH 7.3附带的“ ProxyJump”功能。 This depends upon the ability to remotely login as root, which may not be an option, depending on your environment. 这取决于以root身份远程登录的能力,根据您的环境,这可能不是一个选择。

ssh -J root@server1 testuser@server2

My problem was solved when I added each one of them to the fish functions folder: 当我将其中每个添加到fish函数文件夹时,我的问题已解决:

~/.config/fish/functions 〜/的.config /鱼/功能

I just created a file called myfunction.fish and inside of that file I pasted the function definition: 我刚刚创建了一个名为myfunction.fish的文件,并在该文件的内部粘贴了函数定义:

function myfunction 
     ssh -t testuser@server1 'sudo ssh -t testuser@server2' 
end

saved it, exited fish and now that function is permanent. 保存它,退出鱼,现在该功能是永久性的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM