如何通过 SSH 连接到 colima 实例
寻找通过 SSH 连接到 colima 所需的步骤,这太新了,而且文档有点稀缺。我需要复制卷,运行 scp
似乎是理想的选择。
Looking for the steps needed to SSH into colima
, this is too new and the documentation is a bit scarce. I need to copy over the volumes, and running scp
seems ideal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
这是我解决问题的方法:
1。设置别名以方便使用
首先,将这些别名分别添加到您的 .bashrc
/.zshrc
文件中,以简化您将用于与 Colima 交互的命令:
alias colima_ssh='~/scripts/colima_ssh.sh'
alias colima_scp_from_host_to_vm='~/scripts/colima_scp_from_host_to_vm.sh'
alias colima_scp_from_vm_to_host='~/scripts/colima_scp_from_vm_to_host.sh'
<强>2。脚本设置
从此文件夹下载上面代码片段中列出的脚本: https://github.com/ciechanowiec/linux_mantra/tree/master/resources/scripts。这些脚本有助于 SSH 连接过程以及主机和 Colima 实例之间的安全文件传输。重要的是,这些脚本以 Colima root 身份执行命令,确保您拥有各种操作所需的权限。以下是 colima_ssh.sh
的基本示例:
#!/bin/bash
tmpconfig=$(mktemp)
(cat "$HOME/.colima/ssh_config" | grep --invert-match "^ ControlPath\| ^User"; echo " ForwardAgent=yes") > "$tmpconfig"
ssh -F "$tmpconfig" "$USER@colima" "sudo mkdir -p /root/.ssh/; sudo cp ~/.ssh/authorized_keys /root/.ssh/authorized_keys"
ssh -F "$tmpconfig" root@colima
确保通过运行 chmod +x ~/scripts/*.sh 使这些脚本可执行。
3 。用法
有了这些脚本,您就可以轻松管理 SSH 会话和 SCP 传输。
通过 SSH 连接到 Colima:
colima_ssh
将文件从虚拟机传输到主机:
colima_scp_from_vm_to_host
要将文件从主机传输到 VM:
colima_scp_from_host_to_vm
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
最快的答案
colima ssh
使用
ssh
的快速答案当我这样做时,这里是
scp
:我很乐意已经用文件描述符编写了此内容,不幸的是,当您在
-F
参数中传递文件描述符时,ssh 不喜欢它,例如:ssh -F <(limactl show-ssh --格式配置科利马) lima-colima
使用 root
如果您需要以
root
身份进行身份验证,例如ssh -F $tmpconfig root@lima-colima
您会注意到它不起作用,您的用户将始终被使用,以下是更改该用户的步骤。上面的命令稍微更改为:
使用 ~/.ssh/config
如果您要经常使用
ssh
进入colima
,则始终可以跳过所有大惊小怪,只需将其添加到您的~/.ssh/config
中,然后将其称为“正常”即可。然后“正常”调用
ssh
/scp
:就我个人而言,我不喜欢弄乱我的
~/.ssh/config
,但是做最适合你的事情。Quickest answer
colima ssh
Quick-ish answer using
ssh
While i'm at it, here is the
scp
:I would love to have written this with a file descriptor, unfortunately, ssh does not like it when you pass a file descriptor in the
-F
argument, such as:ssh -F <(limactl show-ssh --format config colima) lima-colima
Use root
If you need to auth as
root
such asssh -F $tmpconfig root@lima-colima
you'll notice it won't work, your user will always be used, here are the steps to change that.The command above changes slightly to:
Using ~/.ssh/config
If you're going to be
ssh
-ing intocolima
a lot, you can alway just skip all the fuss and simply add it into your~/.ssh/config
and just call it "normally".And then just call
ssh
/scp
"normally":Personally, I don't like to clutter my
~/.ssh/config
, but do what best works for you.