如何通过 SSH 进入 Chrome 操作系统?

如何通过 SSH 进入 Chrome 操作系统?

我可以ssh从我的 Google Pixel Slate 转移到任何其他电脑。没问题。

我无法ssh从任何其他计算机进入 Chrome OS。我认为这是因为 shell 是作为 VM 运行的,它甚至有自己的一组 IP 地址,与 Chrome OS 使用的 IP 地址不同。

那么问题是,有没有办法通过 SSH 进入 Chrome OS?可能是某种 NAT?

答案1

对于大多数人来说,最好的选择是通过 SSH 进入 Linux Beta 终端 (Crostini)。这样,您就可以访问在 Chromebook 上运行的完整 Linux VM,并且可以通过 APT 安装在 Chromebook 桌面上运行的 Linux 应用程序。

通过 Linux Beta 进行 SSH 是迄今为止最简单的方法,并且仍然允许您将文件 SCP 到您的 Chromebook、打开图像、播放音频文件以及执行更多功能。

带有照片和代码的详细说明可以在这里找到...

https://www.hackershark.com/2021/05/13/how-to-ssh-into-your-chromebook-through-linux-beta/

概述

  1. 删除 /etc/ssh/sshd_not_meant_to_be_run 文件
  2. 将 SSH 配置文件中的 SSH 端口设置为 1024 以上的自定义端口
  3. 重新启动 SSH 服务器以使新更改生效
  4. 在 Chromebook 设置中转发自定义端口
  5. 通过 SSH 连接到您的 Chromebook

答案2

正如您所提到的,根据您的目标,有几种访问 ChromeOS 设备的选项。最简单的方法是在 Crostini 中启用 SSH,并使用最新 ChromeOS 版本中的新选项设置端口转发。第二个最简单的方法是 Crouton,它需要开发人员模式,但仍可以保留许多系统安全功能。最后,最难、最不“安全”的是配置“主机”ChromeOS 运行 SSH 服务器,但这需要删除许多使 Chromebook 成为真正可靠的开发平台的安全保护措施。

可能有很多帖子介绍了通过 SSH 进入 Crostini 或 Crouton,因此我只会介绍“困难”的选项,并会尝试回来更新一些其他选项的链接,因为我遇到了针对这些选项的一致有效和最佳实践的帖子。

困难模式又称 YOLO:

如果您想要通过 SSH 进入实际主机操作系统,则需要通过切换到开发人员模式来启用 SSH 服务(在转换过程中会清除所有数据)。您可以在重置后设置期间选择启用“调试选项”的选项,但我发现这实际上会在以后导致一些问题,因此我建议您像平常一样连接到互联网并登录。

注意:切换到开发人员模式会设置固件标志,即使执行 Powerwash 或从 USB 恢复也无法将系统从开发人员模式更改回正常模式。您必须在出现开发人员模式警告时按空格键,或者在登录后从 Crosh shell 运行特定命令才能更改开发人员模式设置,出于安全目的,这样做会触发所有数据的擦除。

如果您想通过 SSH 进入您的 ChromeOS 主机操作系统,您需要禁用 rootfs 只读保护,请注意,这会大大降低系统的安全性,并且进行错误的更改或删除错误的文件(或损坏的脚本或滥用您访问权限的恶意软件)可能会导致 ChromeOS 停止启动,迫使您使用 USB 恢复或执行 Powerwash,从而删除您的所有用户数据。

禁用 rootfs 保护后,您可以按照 ChromeOS 源中的指示启用 SSH 服务。

有 3 个选项,第一个是调试,我建议跳过;第二个是我认为最好的,因为您可以禁用密码 SSH 并删除不安全的“测试密钥”,因为它们是公开的;第三个需要在每次重启后手动运行 sshd,如果您需要远程/无人值守访问您的 Chromebook/Chromebox,这可能不是您想要的。不过对于第三个选项,只要您可以正确设置文件的文件权限authorized_keys并将其存储在/usr/local/ChromeOS 在更新期间不会触及的位置,您就可以避免使用“测试密钥”。

https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/chromeos-base/chromeos-sshd-init/files/openssh-server.conf.README#25

Copyright 2015 The Chromium OS Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.

------------------------------
Instructions for enabling sshd
------------------------------
Normally base images will not automatically start sshd on boot. If sshd is
needed, below are a few recommended ways to start it, from simplest to most
complicated.
1. OOBE debugging features.
  This is the easiest way to enable sshd, but if OOBE has already been bypassed
  the machine will have to be powerwashed first to get back to OOBE.
  Enabling the OOBE debugging features will cause sshd to start automatically
  on each boot, and both password and test key access will be enabled.
  For more information on OOBE debugging features, see
  dev.chromium.org/chromium-os/how-tos-and-troubleshooting/debugging-features.
2. Run a helper program.
  An executable named dev_features_ssh is available to enable sshd. Rootfs
  verification must be removed first or the helper program will have no effect.
  This will cause sshd to start automatically on each boot with test key
  access. Password access can optionally be enabled after rootfs verification
  has been removed.
  # Remove rootfs verification.
  $ /usr/share/vboot/bin/make_dev_ssd.sh --remove_rootfs_verification
  $ reboot
  # Install sshd startup files.
  $ /usr/libexec/debugd/helpers/dev_features_ssh
  # Allow password access (optional).
  $ passwd
3. Manually start sshd.
  This is the least convenient option, but doesn't require OOBE or rootfs
  verification removal, so can be used without changing the system too much.
  Unlike the above methods, this will not auto-start sshd on boot.
  Additionally, password access is not possible without rootfs verification
  removal, so test keys must be used to SSH into the device.
  # Create host keys (only needs to be done once).
  $ mkdir -p /mnt/stateful_partition/etc/ssh
  $ ssh-keygen -f /mnt/stateful_partition/etc/ssh/ssh_host_rsa_key -N '' -t rsa
  $ ssh-keygen -f /mnt/stateful_partition/etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
  # Open firewall and start sshd (must be done on every boot).
  $ iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  $ /usr/sbin/sshd \
    -oAuthorizedKeysFile=/usr/share/chromeos-ssh-config/keys/authorized_keys

答案3

Linux 容器发生了一些变化。它现在可以向前端口,但仅限于非特权端口号(1024 及以上)。

端口 2222 上已有一个 SSH 守护程序在运行。这会为 ChromeOS 启动容器做一些事情,并且它是一个仅限 SFTP 的服务器。

您可以做的是安装您自己的 SSH 守护程序并在不同的端口上运行它(我使用 2223)并使用上面给出的主机操作系统中的端口转发功能。

这很不方便,但是当您停止然后启动容器时,端口转发不会恢复。停止容器后,您必须在 Linux 设置选项卡中手动启动转发。

如果你确实让它工作了,记得备份你的 Linux 容器。Linux 容器可能会损坏,无法从终端应用程序启动。

如果容器不是从终端应用程序启动的,则无法启动端口转发。(有一种方法可以使用 CROSH 手动启动容器,然后使用 termina 和 lxc。如果终端不再启动容器而您想要进入该容器,则可以使用此方法。)

相关内容