-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
virtme: enable ssh support #210
Conversation
37d6cdf
to
67cb602
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for looking at this! It looks good, just a few questions, mainly around the new script and options.
7b53b12
to
14a9d94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the new version!
It looks good to me, apart a few missing mkdir -p
. I also added a few questions and suggestions, but they might not require changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, a few more comments :)
But only one thing to change I think to properly fill authorized_keys
file.
About the host keys, thanks for clarifying. I think most VM managers automatically generate new keys, but they also give the option to pass some pre-generated keys (using cloud-init for example) with special config options. We can probably follow the same approach, auto-generate them for now and in the future add an option to pass some pre-generate host keys if it's really needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the last update!
This last version looks good to me, and I tested it.
I have just two minors comments on the sshd script, but you can ignore them and merge directly if you prefer.
Add support for specifying `--server ssh`, to automatically start and configure sshd in the virtme-ng guest, and `--client ssh` to connect to a virtme-ng guest via SSH. The server's port can be customized with the `--port NUM` option (default is 2222). Example usage (start a vng instance with sshd enabled): $ vng --server ssh --port 2222 In another shell session on the host, connect to the running instance as a client: $ vng --client ssh --port 2222 Note that it's also possible to use ssh or scp directly, the --client option is provided for convenience and to be consistent with the vsock option. Signed-off-by: Andrea Righi <arighi@nvidia.com>
Simplify the remote console and ssh options for the vng front-end: - to start a console or ssh server: $ vng --console [PORT] $ vng --ssh [PORT] - to start a console or ssh client session: $ vng --console-client [PORT] $ vng --ssh-client [PORT] Signed-off-by: Andrea Righi <arighi@nvidia.com>
@matttbe I've applied your patch to I think this PR is decent enough for a merge at this point and we can improve things in-tree later. Moreover, after this PR is merged I was considering to cut a new release, because we have some really cool features. :) Thank you so much for all the help on this! |
Thank you!
Sounds good to me!
Good idea! Once released, I will use it in my script to use the console instead of the serial!
You are welcome! Thank you for the modifications and the different updates! |
Thanks a lot for working on this feature! I just tried to test it, and the
The same happens when trying to connect with plain ssh:
Is it something wrong with my machine? I mean, I never really playing with portfwd or anything like that, so I'm not sure what can be wrong in this case: if it's related to vng or something on my machine's ssh. Also, I installed virtme-ng using pipx:
Inside the virtme-ng clonned dir. |
Hi @marcosps, to make sure I understand, when you say it works, you mean that you're able to ssh into the first instance, but other (new) instances are not working? Or even the first one is not working? |
@marcosps thank you for testing it! Can you |
@arighi it "works" because I see the VM started (the server), and QEMU is running. IIUC, by using --ssh on the "server" I would still see a bash session on the "server" as the same as before, and only the --ssh-client on a different session would allow me to "join" in the same VM, right?
Nope: |
This feature has a few assumptions: the user has a "normal" key at the traditional place ( Maybe best to check inside the VM what's there: sshd running? |
@marcosps you can also try to run |
Yep, sshd is installed, I'm trying to ssh into the VM with the same user, by "overlayfs in the home dir", you mean, having overlayfs support on the VM? if yes, than I'm covered. I also have the "normal" keys in my ~/.ssh/
Thanks @matttbe and @arighi it seems that my sshd is failing to start:
I'm using openSUSE Tumbleweed, which already uses the usrmerge (either way, I'm running as a normal user, which doesn't allow me to start sshd either way).... |
...
You need to run the sshd script as root (in the guest), and you probably need to |
Ah, ok ok, makes sense. Sorry about it. I'm now running as root, but I'm still seeing the EACCESS error:
I tried to
So I'm not sure what's going on... starting sshd on my host system as root works, so I'm not sure why this doesn't work... |
Ah ok, makes sense, that's because sshd is trying to access In my case I have the config in |
From the host, can you access |
Or could it be enough to write something in the troubleshooting section in the README file for the moment? |
Yeah, finding the proper location for the confiig file can be tricky, I'd hope that the first path that sshd checks is |
I guess it is hardcoded at build time, using info passed to the
Maybe it is easier to maintain and always use a minimal custom config. At least we would be sure the port is always 22 for example. |
I think all distro are configuring sshd to use the config from m /etc/ssh/sshd_config, if we maintain a small file there we can probably solve 90% of the issues (or worst case we can check a couple of known paths depending on the distro) |
@marcosps @matttbe #212 should fix the EACESS issue. Moreover, I was thinking, why don't we just allow empty password for all users (see arighi/virtme-ng-init#16) and set At the end we don't care about security inside the guest, because it's for testing purposes only, and from a security standpoint it's also safe, because all the filesystem operations are still performed by virtiofsd, that runs as the host user, independently on the user in the guest. |
|
||
# Setup a port forward network interface for the guest. | ||
qemuargs.extend(["-device", "%s,netdev=ssh" % (arch.virtio_dev_type("net"))]) | ||
qemuargs.extend(["-netdev", "user,id=ssh,hostfwd=tcp::%d-:22" % args.port]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on arighi/virtme-ng-init#16 (review), this should be modified:
"hostfwd=tcp:127.0.0.1:%d-:22" % args.port
ahhh, ok, yes, it makes sense that virtiofsd runs as a normal user... thanks a lot for spotting this problem! I'll test your PR to check if that fixes my issue! |
Add support for specifying
--server ssh
, to automatically start and configure sshd in the virtme-ng guest, and--client ssh
to connect to a virtme-ng guest via SSH.The server's port can be customized with the
--port NUM
option (default is 2222).Example usage (start a vng instance with sshd enabled):
$ vng --server ssh --port 2222
In another shell session on the host, connect to the running instance as a client:
$ vng --client ssh --port 2222
Note that it's also possible to use ssh or scp directly, the --client option is provided for convenience and to be consistent with the vsock option.
Edit: additionally, introduce the following shortcuts for convenience, to quickly enable remote connection (either vsock or ssh):
$ vng --console PORT
$ vng --ssh PORT
Example: