Enable incoming SSH traffic to your virtual machine
To enable incoming traffic to your virtual machine, you must create a security rule, this can be done using Hyperstack or the Infrahub API.
Hyperstack
To enable SSH access to your virtual machine in Hyperstack:
-
Within Hyperstack, navigate to the Virtual Machines page.
-
Click on the virtual machine for which you intend to enable SSH access.
-
In the Security Rules section of the virtual machine, click the Enable SSH access button. This action will automatically generate a security rule allowing incoming traffic from any IP (0.0.0.0/0) on port 22 via the TCP protocol.
Before
After
Infrahub API
Send a POST request to /core/virtual-machines/{virtual-machine-id}/sg-rules endpoint replacing virtual-machine-id in the path with the ID of the virtual machine for which you want to enable SSH access, and complete the body of the request as specified below.
- Include the integer ID of the virtual machine that this security rule is being attached to in the path of the request as follows:
/core/virtual-machines/{VM ID HERE}/sg-rules
-
Complete the request body with the following fields and values:
Field Name Field Input Description remote_ip_prefix 0.0.0.0/0 Allows traffic from any source IP address. direction ingress Designates that the security rule is for incoming traffic. ethertype IPv4 Indicates the use of Internet Protocol version 4. protocol icmp Specifies the use of Internet Control Message Protocol. port_range_min 22 Specifies the minimum port value for SSH. port_range_max 22 Specifies the maximum port value for SSH.
Request
curl -X POST https://infrahub-api.nexgencloud.com/core/virtual-machines/{virtual-machine-id}/sg-rules \
-H "accept: application/json" \
-H "api_key: YOUR API KEY" \
-d '{
"remote_ip_prefix": "0.0.0.0/0",
"direction": "ingress",
"ethertype": "IPv4",
"protocol": "tcp",
"port_range_min": 22,
"port_range_max": 22
}'
To authenticate Infrahub API requests, add an authorization header to your API request that contains an API Key as follows:
-H "api_key: YOUR API KEY"