You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编写SSH连接bash脚本遇“文件或目录未找到”错误的排查求助

Fixing Your Raspberry Pi SSH Tunnel Bash Script

Let’s break down the issues with your script and get it working properly:

Key Problems in Your Original Script

  1. Broken Shebang Line:
    Your script starts with #!usr/bin/bash—missing the leading slash (/) before usr, so the system can’t locate the bash interpreter correctly. Additionally, you’ve stuffed the entire xterm command into the shebang line, which is invalid. The shebang should only specify the interpreter (and its optional flags), not the command you want to run.

  2. Smart Quotes Instead of Regular Quotes:
    You’re using curly quotes (“Terminal1“, “.ssh/key_rsa“) instead of standard double quotes ("). Bash doesn’t recognize these smart quotes as string delimiters, so it treats them as part of the filename or command, leading to "file not found" errors.

  3. Leading Space in SSH Target:
    There’s an extra space before pi@192.168.0.107 inside the quotes. This means SSH is trying to connect to a host named pi@192.168.0.107 (with a leading space), which isn’t a valid target.

Corrected Script

Here’s the fixed version of your script:

#!/bin/bash
xterm -title "Terminal1" -hold -e ssh -i ".ssh/key_rsa" "pi@192.168.0.107"

Extra Tips

  • Ensure Key Path is Reliable: If you run the script from a directory other than your home folder, .ssh/key_rsa might not be found. Use an absolute path to avoid this:
    ssh -i "~/.ssh/key_rsa" "pi@192.168.0.107"
    
  • Make the Script Executable: After saving the corrected script, run this command to make it executable:
    chmod +x your_script_name.sh
    

内容的提问来源于stack exchange,提问作者Alfred Wächter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 10:32:36