我经常执行这样的命令:
ssh username@hostname 'bash -s' < bashScriptToExecuteRemotely
Run Code Online (Sandbox Code Playgroud)
我现在有一个案例,bashScriptToExecuteRemotely期望设置某些环境变量。就我而言,假设它们是 FOO=14 和 BAR=giraffe。
我怎样才能让在远程主机上启动的 bash shell 在执行之前设置这些环境变量bashScriptToExecuteRemotely?
我有一个主机 Windows 操作系统,我在我的 Windows 机器上设置了我的 ssh 密钥来访问 github 和其他资源。现在我使用 VMware 播放器安装了一个来宾 Linux 操作系统。我可以在 Linux 机器上重复使用 windows 机器上的私钥吗?如何让 Linux 知道私钥所在的位置。
我有三台机器:
localhosthost1. 但是,它位于运营商级 NAT 之后,因此我无法从 ssh 直接连接到它localhostrelayhost设置为帮助我连接localhost到host1我想SSH从每个localhost并host1到relayhost,然后有relayhost中继从我的ssh连接localhost到host1。
这样的回答表明,我可以创建一个通道relayhost使用ssh -L,如果我知道的URI或IP地址host1。但是,由于运营商级 NAT,我不知道。所以我可以想象一个像这样中继它的过程:
host1,ssh user@relayhostrelayhost 正在监视这个连接,当它看到它说“我要创建一个从我的端口 9999 到这个连接的隧道”localhost,ssh 9999:relayhost这是解决这个问题的正确方法吗?如何进行第 2 步?
我正在尝试从我设备的浏览器访问 HTTP(S) 网站。我的设备只能通过双 SSH 隧道访问该网站。
使用这种技术,我能够将我的 Firefox 浏览器设置为通过我的名为SERVER1.
但是,SERVER1无法访问我需要的网站。幸运的是,SERVER1可以 SSH 到另一个SERVER2可以。
现在,我可以运行:
SERVER1 $ ssh -D 12345 myuser@SERVER2
Run Code Online (Sandbox Code Playgroud)
并从SERVER1to创建另一个隧道SERVER2,但我不清楚如何在没有 firefox on 的情况下执行“firefox”部分SERVER1。
最重要的是,该网站位于非标准端口(假设为 8765)上,所以我不确定它export http_proxy是否可行。
我该怎么办?谢谢
我以这种方式通过 ssh 执行脚本:
ssh user@host 'bash -s' < ./script.sh
Run Code Online (Sandbox Code Playgroud)
问题是,有时,我得到的输出不正确,行是混合的。
在我的情况下,脚本执行不是很新,正常输出是这样的:
...
Note: Ignoring non-mail file: foobar
Note: Ignoring non-mail file: foobar
Note: Ignoring non-mail file: foobar
Processed 93 total files in almost no time.
No new mail.
Run Code Online (Sandbox Code Playgroud)
但有时输出是这样的:
...
Note: Ignoring non-mail file: foobar
Note: Ignoring non-mail file: foobar
Processed 93 total files in almost no time.
No new mail.
Note: Ignoring non-mail file: foobar
Note: Ignoring non-mail file: foobar
Run Code Online (Sandbox Code Playgroud)
并且可以肯定这不是来自 的真正输出notmuch new,该命令以 结尾,No new mail …
我有一台 Windows 10 PC:192.168.84.21
Mac (macOS Sierra):192.168.84.250
iPhone 5s:192.168.84.234
和 Apple TV:192.168.84.122
都连接到同一个网络。我知道这一点是因为我的 iPhone 上有一个应用程序 (Fing),它可以扫描网络并显示所有设备,并且所有设备都会弹出正确的 IP 和设备名称。
路由器是XB6-A,但它使用 Google 的 Wifi Mesh 进行设置,这是我所连接的。
问题:我无法从我的 PC ssh 到 Mac。
我正在使用 PuTTY,这是我正在使用的命令:
pscp -r -pw <password> me@192.168.84.250:Desktop/blank.png C:Users/me/temp
Run Code Online (Sandbox Code Playgroud)
我得到了Fatal: Network error: Connection timed out。
诊断:
PC 和 Mac 都关闭了防火墙。
PC 和 Mac 无法互相 ping 通。
当 PC ping Mac 时,这是响应:
Pinging 192.168.84.250 with 32 bytes of data:
Reply from 192.168.84.21: Destination host unreachable.
Reply from 192.168.84.21: Destination …Run Code Online (Sandbox Code Playgroud) 我已经在我的 Windows 操作系统上安装了适用于 Linux 的 Windows 子系统 (WSL ),并且能够在 Visual Studio 代码编辑器中看到终端。
所以我输入help sshcommand 并点击enter,从那时起我看到大于 ( >) 符号并且无法执行命令。我怎么回来。我尝试使用exit,exit 0,exit -f,quit,killall,什么不是。
我有一个脚本文件./run_app.sh,其中包含以下内容:
ssh -L 8888:localhost:8888 ubuntu@address
./run_website.sh # it should be executed locally
Run Code Online (Sandbox Code Playgroud)
但它试图在远程机器上运行第二行。实际上,我想在我的电脑上运行它。任何的想法?
我的 .ssh/config 文件中有以下条目:
Host myhost
Hostname localhost
User me
ServerAliveInterval 30
ProxyCommand ssh -q external-relay /usr/bin/nc -w 90 localhost 9889
Run Code Online (Sandbox Code Playgroud)
非常简单,它允许我myhost从 NATed 网络外部访问,通过反弹external-relay.
大多数时候我只想通过 SSH 连接到myhost,而不创建任何 SSH 隧道,但有时我想创建各种隧道,用于不同的目的。
现在我只是-L在 ssh 时手动附加隧道条目,myhost但是越来越难以记住我需要哪些端口集用于哪个目的。
我可以将这些自定义端口转发命令添加为别名,但我真正想要的是在我的.ssh/config文件中有单独的命名条目,这些条目基本上创建连接myhost并添加所需的隧道,但我不想复制整个myhostconfig 每次,因为如果/当我更改external-relay,我不想记住在使用它的每个条目中更改它。
有没有办法创建一个从条目继承的myhost条目,并简单地附加该LocalForward特定隧道案例所需的指令?
这就是我想要做的。我想使用本地文件管理器(nautilus、nemo、pcmanfm)连接到服务器 C。我曾经这样做只是写作
sftp://username@ServerC
Run Code Online (Sandbox Code Playgroud)
在位置栏中,或使用连接到服务器选项。但是,现在我不在本地网络中,那么我需要先通过网关服务器。在终端,我跳过门服务器没有任何问题。
正在做
ssh -J gate ServerC
Run Code Online (Sandbox Code Playgroud)
那么问题是:
我如何使用文件管理器来做到这一点?
有没有办法写一种最初考虑网关服务器的SFTP地址?
或者在连接后从终端回调我的本地文件管理器?
(服务器C似乎没有文件管理器,我不知道是否有任何系统的方法来检查这一点,而不是当时查看每个可能的文件管理器)
ssh ×10
linux ×6
bash ×2
ssh-tunnel ×2
gateway ×1
http-proxy ×1
openssh ×1
protocol ×1
script ×1
sftp ×1
shell-script ×1
terminal ×1
tunnel ×1
ubuntu ×1
virtualbox ×1
vmware ×1