Added SSH support, with the ability to override what port is forwarded to the machine

This commit is contained in:
Stuart Howlette 2020-03-19 12:48:02 +00:00
parent cdb4c12170
commit 208c8b1347
2 changed files with 69 additions and 2 deletions

View File

@ -74,6 +74,49 @@ You can also pass optional parameters
--restore : Restore the snapshot.
--snapshot : Create a disk snapshot.
--virgil : Use virgil, if available.
--ssh : Enable SSH to the machine (disabled by default).
--ssh-port : Local port to forward to the machine (default 2222).
```
### SSH Access
SSH access to the QEMU virtual machine can be enabled by using the `--ssh` flag. This will portforward `TCP2222` on the host machine to `TCP22` on the QEMU guest machine. This does not install or start an SSH server within the guest itself, so you will stil need to enable this on a per-guest basis. For Ubuntu guests, you can enable this by installing `openssh-server`.
If the default port overlaps with another service on your host, you can override this with `--ssh-port $PORT`. This will still forward to port `TCP22` on the guest machine.
Example of usage: -
```
$ ./quickemu.sh --vm mate.conf --ssh --ssh-port 1111
Starting mate.conf
- BIOS: Legacy
- Disk: /home/$USER/Applications/quickemu/ubuntu-mate/focal-desktop-amd64.qcow2
- Size: 20G
- ISO: /home/$USER/Applications/quickemu/ubuntu-mate/focal-desktop-amd64.iso
- CPU: 2 Core(s)
- RAM: 2G
- UI: sdl
- GL: on
- smbd: /home/stuh84 will be exported to the guest via smb://10.0.2.4/qemu
$ ssh quickemu@localhost -p 1111
quickemu@localhost's password:
Welcome to Ubuntu Focal Fossa (development branch) (GNU/Linux 5.4.0-18-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
quickemu@ubuntu-mate:~$
```
## TODO
@ -81,4 +124,4 @@ You can also pass optional parameters
- [x] Make display configuration more robust
- [x] Improve stdout presentation
- [x] Make disk image optionally size configurable
- [ ] Improve snapshot management
- [ ] Improve snapshot management

View File

@ -133,6 +133,19 @@ function vm_boot() {
echo " - smbd: %{HOME} will not be exported to the guest. 'smbd' not found."
fi
# Creates a port-forward from the host machine to the QEMU guest
# By default, if not port is specified (with --ssh-port $SSH_PORT), TCP port 2222 is used
# Access to the QEMU machine is then available via: -
#
# ssh $USER@localhost -p $SSH_PORT
#
if [ ${SSH} -eq 1 ]; then
SSH_FWD=",hostfwd=tcp::${SSH_PORT}-:22"
else
SSH_FWD=""
fi
#echo " - QEMU: qemu-${ENGINE}"
# Boot the iso image
qemu-${ENGINE} ${BIOS} \
@ -144,7 +157,7 @@ function vm_boot() {
-m ${ram} \
-smp ${cores} \
-net nic,model=virtio \
-net user"${SAMBA}" \
-net user"${SAMBA}""${SSH_FWD}" \
-rtc base=localtime,clock=host \
-soundhw hda \
-usb -device usb-kbd -device usb-tablet \
@ -168,6 +181,8 @@ function usage() {
echo " --restore : Restore the snapshot."
echo " --snapshot : Create a disk snapshot."
echo " --virgil : Use virgil, if available."
echo " --ssh : Enable SSH to the machine (disabled by default)."
echo " --ssh-port : Local port to forward to the machine (default 2222)."
exit 1
}
@ -178,6 +193,8 @@ ENABLE_EFI=0
ENGINE="system-x86_64"
RESTORE=0
SNAPSHOT=0
SSH=0
SSH_PORT=2222
VM=""
while [ $# -gt 0 ]; do
@ -197,6 +214,13 @@ while [ $# -gt 0 ]; do
-virgil|--virgil)
ENGINE="virgil"
shift;;
-ssh|--ssh)
SSH=1
shift;;
-ssh-port|--ssh-port)
SSH_PORT=$2
shift
shift;;
-vm|--vm)
VM="$2"
shift