可以。新内网机器只需要主动连中心端,不需要入站端口。
中心信息:
Server: http://60.205.90.109:22222
Tenant ID: 879858ec-c6f8-470e-9bf0-89804aa6911d
Namespace: admin
无 root / 无 Docker 方案
在新机器上登录到你要暴露的普通用户,比如 alice,执行:
SERVER='http://60.205.90.109:22222'
TENANT='879858ec-c6f8-470e-9bf0-89804aa6911d'
DEVICE='adbiza-ptg' # 改成唯一名字,只用小写字母/数字/短横线
mkdir -p ~/.local/bin ~/.local/share/shellhub ~/.config/shellhub ~/.config/systemd/user
case "$(uname -m)" in
x86_64|amd64) ASSET='shellhub-agent-linux-amd64.gz' ;;
aarch64|arm64) ASSET='shellhub-agent-linux-arm64.gz' ;;
armv7l) ASSET='shellhub-agent-linux-armv7.gz' ;;
armv6l) ASSET='shellhub-agent-linux-armv6.gz' ;;
i386|i686) ASSET='shellhub-agent-linux-386.gz' ;;
*) echo "unsupported arch: $(uname -m)" >&2; exit 1 ;;
esac
curl -fsSL "https://github.com/shellhub-io/shellhub/releases/download/v0.25.0/$ASSET" \
| gzip -dc > ~/.local/bin/shellhub-agent
chmod +x ~/.local/bin/shellhub-agent
~/.local/bin/shellhub-agent version
然后设置 ShellHub SSH 密码。这个密码是之后通过 ShellHub 连这台机器时用的,不是 Linux 系统密码:
read -r -s -p "ShellHub SSH password: " PASS; echo
HASH="$(openssl passwd -6 "$PASS")"
cat > ~/.config/shellhub/agent.env <<EOF
SHELLHUB_SERVER_ADDRESS=$SERVER
SHELLHUB_TENANT_ID=$TENANT
SHELLHUB_PRIVATE_KEY=$HOME/.local/share/shellhub/shellhub.key
SHELLHUB_SINGLE_USER_PASSWORD=$HASH
SHELLHUB_PREFERRED_HOSTNAME=$DEVICE
SHELLHUB_LOG_LEVEL=info
SHELLHUB_TRANSPORT_VERSION=2
EOF
chmod 600 ~/.config/shellhub/agent.env
创建用户级 systemd 服务:
cat > ~/.config/systemd/user/shellhub-agent.service <<'EOF'
[Unit]
Description=ShellHub Agent
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
EnvironmentFile=%h/.config/shellhub/agent.env
ExecStart=%h/.local/bin/shellhub-agent
Restart=always
RestartSec=10
WorkingDirectory=%h
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now shellhub-agent.service
systemctl --user status shellhub-agent.service
看日志确认连上:
journalctl --user -u shellhub-agent.service -f
看到类似 Server connection established 就可以去中心 Web UI 里接受设备:
http://60.205.90.109:22222
Devices -> Pending -> Accept
连接方式
假设新机器 Linux 用户是 alice,你设置的 DEVICE=newbox:
ssh -p 22222 -l '[email protected]' 60.205.90.109
本机 SSH config 可以加:
Host newbox
HostName 60.205.90.109
Port 22222
User [email protected]
IdentityFile ~/.ssh/id_ed25519
之后:
ssh newbox
注意
如果新机器没有 root,用户级 systemd 服务可能在你退出登录后被系统停掉。检查:
loginctl show-user "$USER" -p Linger
如果是 Linger=no,最好让有 root 的人执行:
sudo loginctl enable-linger alice
有 root/Docker 的机器可以用官方一行安装脚本,但你之前的场景更适合上面这个 native agent 方案。