How to Setup Serial-Console to Access your VM
Introduction
There may be moments where you need to access your VM when SSH is not working. Serial-console access provides a "backdoor" connection to your VM.
Prerequisites
Configuring serial-console access is important to setup upon creating a VM or when you have SSH access to an already running VM.
- Make sure you have the Crusoe CLI installed
Instructions to setup Serial-Console
1. Configuring serial-console access when a VM is running via passwd.
-
To setup serial-console access to an already running VM that is SSH'able, you need to set an appropriate user and password by establishing an SSH connection and using `passwd` to set a password:
sudo passwd $(whoami)
- This will allow you to set a password for the currently logged in user.
- Then in your terminal, serial console is available via the CLI, using the
serial-console
command:
crusoe compute vms serial-console \
--name $NAME_of_VM \
--port-num PORT
- This will open a connection to the serial console on the VM.
-
- --name is the name of the VM you are wanting to connect to.
- --port-num can be from 1-4, with a default of 1 if --port-num is not specified.
-
2. Configuring serial-console access when a VM is running via lifecycle script.
-
Once a VM is created, you can modify the startup script directly on the VM by editing the files in
/usr/local/bin/crusoe
- Include in the startup file:
#!/bin/bash
echo "$user:$password" | chpasswd
- Make sure to replace $user and $password with a user that already exists in your VM, along with a password of your choice that is not easily attainable. Changes to this script take effect immediately on the next shutdown or startup.
3. Configuring serial-console access when creating a VM in the UI.
- When creating a VM, you'll be prompted with a startup and shutdown script after assigning a Public Key. Screenshot of the startup and shutdown script page is below
- Include the following in the Startup script:
#!/bin/bash
echo "$user:$password" | chpasswd
- Make sure to replace $user and $password with a user that already exists in your VM, along with a password of your choice that is not easily attainable. You can modify the startup script at
/usr/local/bin/crusoe
4. Configuring serial-console access when creating a VM in the CLI.
- When creating a VM in the CLI, you have the option to include your own startup script file with the
--startup-script
flag. The code to create a VM along with including a startup script is below:
crusoe compute vms create \
--name my-vm \
--type a40.1x \
--location us-northcentral1-a \
--image ubuntu22.04:latest \
--startup-script /path/to/script/startup.sh
--keyfile ~/.ssh/id_ed25519.pub
- Include in the Startup script:
#!/bin/bash
echo "$user:$password" | chpasswd
- Make sure to replace $user and $password with a user that already exists in your VM, along with a password of your choice that is not easily attainable.
- Please note: Having a password stored in a startup script can lead to great security risks so please use discretion.
Next Steps
Once you connect to your VM via serial-console, you'll gain access to your VM. From here, you can check SSHd status, check other services that are running in your VM, reboot the VM or anything else to help get you unblocked.
Comments
0 comments
Article is closed for comments.