在 Chrome OS 的用户终端 (crosh) 中使用 sudo 权限
💡
原文中文,约1300字,阅读约需3分钟。
📝
内容提要
在 Chrome OS 的用户终端 (crosh) 中使用 sudo 权限的步骤包括:打开 VT-2 终端并登录,创建 ed25519 和 rsa 类型的密钥,复制密钥到 sshd 服务器目录,设置公钥以允许 ssh 连接。修改 ~/.bashrc 预设命令后,启动 sshd 服务器即可在 crosh 中使用 sudo 权限。每次重启后需重新启动 sshd 服务器。
🎯
关键要点
- 按 Ctrl + Alt + F2 打开 VT-2 终端,使用 chronos 用户登录。
- 创建 ed25519 和 rsa 类型的密钥,使用命令 ssh-keygen -t ed25519 和 ssh-keygen -t rsa。
- 将密钥复制到 sshd 服务器所需的目录,使用命令 sudo mkdir -p /mnt/stateful_partition/etc/ssh/ 和 sudo cp ~/.ssh/id_ed25519 /mnt/stateful_partition/etc/ssh/ssh_host_ed25519_key 等。
- 允许公钥建立 ssh 连接,使用命令 cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys 和 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys。
- 在 ~/.bashrc 中预设命令以方便使用,使用命令 echo "alias vt2port=\"sudo /usr/sbin/sshd -p 6969\"" >> ~/.bashrc 和 echo "alias vt2connect=\"ssh 127.1 -p 6969\"" >> ~/.bashrc。
- 输入 vt2port 启动 sshd 服务器,注销 VT-2 后返回 Chrome OS。
- 在 crosh 中输入 shell 进入终端,使用 vt2connect 连接到 sshd 服务器,之后可以使用 sudo 命令。
- 每次重启后需重新启动 sshd 服务器,步骤为:进入 VT-2 登录 chronos 用户,输入 vt2port 开启 sshd 服务器,注销 VT-2 返回 Chrome OS。
❓
延伸问答
如何在 Chrome OS 中打开 VT-2 终端?
按 Ctrl + Alt + F2 打开 VT-2 终端。
在 Chrome OS 中使用 sudo 权限需要哪些步骤?
需要创建密钥、复制密钥到指定目录、设置公钥、修改 ~/.bashrc、启动 sshd 服务器。
如何创建 ed25519 和 rsa 类型的密钥?
使用命令 ssh-keygen -t ed25519 和 ssh-keygen -t rsa 创建密钥。
如何在 ~/.bashrc 中设置命令以方便使用?
可以使用命令 echo "alias vt2port=\"sudo /usr/sbin/sshd -p 6969\"" >> ~/.bashrc 和 echo "alias vt2connect=\"ssh 127.1 -p 6969\"" >> ~/.bashrc。
每次重启后如何重新启动 sshd 服务器?
进入 VT-2 登录 chronos 用户,输入 vt2port 开启 sshd 服务器,然后注销 VT-2 返回 Chrome OS。
在 crosh 中如何连接到 sshd 服务器?
在 crosh 中输入 shell 进入终端,然后输入 vt2connect 连接到 sshd 服务器。
➡️