AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 447780
Accepted
Tom Mekken
Tom Mekken
Asked: 2018-06-05 05:39:22 +0800 CST2018-06-05 05:39:22 +0800 CST 2018-06-05 05:39:22 +0800 CST

ssh 通过需要代理的身份验证

  • 772

在工作中,我们当然有公司的代理。我需要通过 ssh 连接到公司网络之外的一些机器。但是,代理需要身份验证。

假设我们有以下变量:

proxy_user="<username I need to authenticate at the proxy>"
proxy_pass="<password I need to authenticate at the proxy>"
proxy_serv="<hostname of the proxy>"
proxy_port=<port of the proxy>
ssh_user="<remote username I need to login on the ssh-machine>"
ssh_serv="<remote password I need to login on the ssh-machine>"
ssh_port=<ssh-port>

如下设置环境变量 http_proxy 和 https_proxy 时,像 wget 这样的工具可以正常工作(在远程服务器上,还安装了一个 web_server):

$ export env http_proxy="http://$proxy_user:$proxy_pass@$proxy_serv:$proxy_port"

$ wget $ssh_serv
Connecting to <proxy_serv>... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html’

但是使用 ssh 它不起作用:

$ ssh $ssh_user@$ssh_server:$ssh_port
ssh: Could not resolve hostname <ssh_server>:<ssh_port> Temporary failure in name resolution

在谷歌搜索了一下之后,我发现 ssh 需要一个“ProxyCommand”。此处不再推荐“nc”;应使用“ssh -W”。但我找不到需要身份验证的示例。到目前为止我尝试过:

ssh -o "ProxyCommand='ssh -W %h:%p $proxy_user:$proxy_pass@$proxy_serv:$proxy_port'" $ssh_user@$ssh_serv:$ssh_port

我想我在某处遗漏了一些东西,但找不到好的提示(无论是在手册中,还是在谷歌上)。

我希望你们中的一些人可以帮助我。

ssh proxy
  • 3 3 个回答
  • 12935 Views

3 个回答

  • Voted
  1. Best Answer
    Tom Mekken
    2018-06-26T04:39:24+08:002018-06-26T04:39:24+08:00

    现在经过几个小时的谷歌搜索,我终于在“开瓶器”的帮助下让它为我工作了。我的 ssh-server 目前正在端口 443 上运行(还没有尝试过,是否也可以在 22 上运行)。

    ~/.ssh/config

    Host <my.ssh.server>
        ProxyCommand corkscrew <my.companies.proxy> <proxy.port> %h %p ~/corkscrew-auth
    

    ~/.corkscrew-auth

    <proxies.username>:<proxies.password>
    

    现在我可以通过以下方式连接到我的服务器:

    ssh <remote.user>@<my.ssh.server> -p 443
    
    • 1
  2. Kahn
    2018-06-05T06:08:38+08:002018-06-05T06:08:38+08:00

    只是为了测试-您是否考虑过使用nc?当我尝试让代理命令工作时,我通常在配置级别这样做:/root/.ssh/config

    例如,配置将具有以下内容:

    Host ssh.example.com
        ProxyCommand ssh [email protected] nc %h %p
    

    这就是说,每当您连接到 ssh.example.com 时,它都会使用下面的 ProxyCommand。我建议试一试,如果您绝对不能使用 netcat 实用程序,我相信我们可以想到一个解决方法。

    • 0
  3. Eduardo Osquel Pérez Rivero
    2022-07-09T08:12:40+08:002022-07-09T08:12:40+08:00

    这是我的解决方案:

    首先安装这个 Debian/Ubuntu/Mint 软件包:

    apt-get install connect-proxy
    

    如果您在代理后面使用身份验证,请导出凭据:

    导出 HTTP_PROXY_USER= <用户>
    导出 HTTP_PROXY_PASSWORD= <密码>
    

    访问 ssh 配置文件/etc/ssh/ssh_config并设置远程主机端口:

    Port 443
    

    设置服务器活动间隔以避免连接丢失:

    ServerAliveInterval 20
    

    设置 ProxyCommand 以使用连接最近安装的包:

    ProxyCommand connect -H <proxy> : <port> %h %p
    

    关闭 ssh 配置文件,然后您就可以执行 ssh 连接了:

    ssh -N -D localhost:1080 <远程用户> @ <远程主机>
    

    打开 Firefox,将网络设置配置为仅使用 Socket 5:

    主机:localhost端口:1080

    也启用Proxy DNS when using SOCKS v5。

    最后,在 Firefox 搜索选项卡中,键入以下内容:

    about:config
    

    查找network.proxy.allow_hijacking_localhost并设置为true.

    现在您已准备好在代理后面连接并使用 Firefox 在创建的隧道后面进行探索。

    • 0

相关问题

  • 为什么 ssh 实用程序被视为 pty?

  • Auto-SSH 手动工作,但不在后台工作

  • 远程运行 X 应用程序,在远程主机上运行 GUI [关闭]

  • rsync 端口 22 和 873 使用

  • SCP突然中止:管道损坏,消息验证码不正确

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    ssh 无法协商:“找不到匹配的密码”,正在拒绝 cbc

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    如何卸载内核模块“nvidia-drm”?

    • 13 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Wong Jia Hau ssh-add 返回:“连接代理时出错:没有这样的文件或目录” 2018-08-24 23:28:13 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST
  • Martin Hope
    Bagas Sanjaya 为什么 Linux 使用 LF 作为换行符? 2017-12-20 05:48:21 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve