如何通过 SSH 连接到 colima 实例

发布于 01-10 08:28 字数 83 浏览 4 评论 0原文

寻找通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伪心2025-01-17 08:28:09

最快的答案

colima ssh

使用 ssh 的快速答案

(tmpconfig=$(mktemp); limactl show-ssh --format config colima > $tmpconfig; ssh -F $tmpconfig lima-colima)

当我这样做时,这里是 scp

(tmpconfig=$(mktemp); limactl show-ssh --format config colima > $tmpconfig; scp -F $tmpconfig lima-colima:/path/to/somewhere/ .)

我很乐意已经用文件描述符编写了此内容,不幸的是,当您在 -F 参数中传递文件描述符时,ssh 不喜欢它,例如:ssh -F <(limactl show-ssh --格式配置科利马) lima-colima


使用 root

如果您需要以 root 身份进行身份验证,例如 ssh -F $tmpconfig root@lima-colima 您会注意到它不起作用,您的用户将始终被使用,以下是更改该用户的步骤。

(
tmpconfig=$(mktemp);
# Need to remove the 'ControlPath' and 'User', and add 'ForwardAgent'
(limactl show-ssh --format config colima | grep -v "^  ControlPath\|  ^User"; echo "  ForwardAgent=yes") > $tmpconfig;
# Setup root account
ssh -F $tmpconfig $USER@lima-colima "sudo mkdir -p /root/.ssh/; sudo cp ~/.ssh/authorized_keys /root/.ssh/authorized_keys"
)

上面的命令稍微更改为:

(tmpconfig=$(mktemp); (limactl show-ssh --format config colima | grep -v "^  ControlPath\|  ^User"; echo "  ForwardAgent=yes") > $tmpconfig; ssh -F $tmpconfig root@lima-colima)

使用 ~/.ssh/config

如果您要经常使用 ssh 进入 colima,则始终可以跳过所有大惊小怪,只需将其添加到您的 ~/.ssh/config 中,然后将其称为“正常”即可。

# run this ONLY ONCE!!!
limactl show-ssh --format config colima >> ~/.ssh/config

然后“正常”调用 ssh/scp

ssh lima-colima
scp lima-colima:/path/blah/foo .

就我个人而言,我不喜欢弄乱我的 ~/.ssh/config,但是做最适合你的事情。

Quickest answer

colima ssh

Quick-ish answer using ssh

(tmpconfig=$(mktemp); limactl show-ssh --format config colima > $tmpconfig; ssh -F $tmpconfig lima-colima)

While i'm at it, here is the scp:

(tmpconfig=$(mktemp); limactl show-ssh --format config colima > $tmpconfig; scp -F $tmpconfig lima-colima:/path/to/somewhere/ .)

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 as ssh -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.

(
tmpconfig=$(mktemp);
# Need to remove the 'ControlPath' and 'User', and add 'ForwardAgent'
(limactl show-ssh --format config colima | grep -v "^  ControlPath\|  ^User"; echo "  ForwardAgent=yes") > $tmpconfig;
# Setup root account
ssh -F $tmpconfig $USER@lima-colima "sudo mkdir -p /root/.ssh/; sudo cp ~/.ssh/authorized_keys /root/.ssh/authorized_keys"
)

The command above changes slightly to:

(tmpconfig=$(mktemp); (limactl show-ssh --format config colima | grep -v "^  ControlPath\|  ^User"; echo "  ForwardAgent=yes") > $tmpconfig; ssh -F $tmpconfig root@lima-colima)

Using ~/.ssh/config

If you're going to be ssh-ing into colima a lot, you can alway just skip all the fuss and simply add it into your ~/.ssh/config and just call it "normally".

# run this ONLY ONCE!!!
limactl show-ssh --format config colima >> ~/.ssh/config

And then just call ssh/scp "normally":

ssh lima-colima
scp lima-colima:/path/blah/foo .

Personally, I don't like to clutter my ~/.ssh/config, but do what best works for you.

怀里藏娇2025-01-17 08:28:09

这是我解决问题的方法:

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<科利马路径>

Here is how I solved it:

1. Setup Aliases for Convenience

First, add these aliases to your .bashrc/.zshrc files respectively to simplify the commands you'll use to interact with 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. Scripts Setup

Download the scripts listed in the snippet above from this folder: https://github.com/ciechanowiec/linux_mantra/tree/master/resources/scripts. The scripts facilitate the SSH connection process and secure file transfer between your host and the Colima instance. Importantly, these scripts execute commands as Colima root, ensuring that you have the necessary permissions for various operations. Here’s a basic example of what colima_ssh.sh looks like:

#!/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

Make sure to make these scripts executable by running chmod +x ~/scripts/*.sh.

3. Usage

With these scripts in place, you can effortlessly manage your SSH sessions and SCP transfers.

To SSH into Colima:

colima_ssh

To transfer a file from VM to host:

colima_scp_from_vm_to_host <path-on-colima> <path-on-host>

To transfer a file from host to VM:

colima_scp_from_host_to_vm <path-on-host> <path-on-colima>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文