如何设置AWS Lightsail VM的主机名?

查看我的新Lightsail VM上的cloudinitconfiguration,似乎是在与元数据API进行通信以获取主机名等设置。 我没有看到任何轻量级的UI组件来设置主机名,但是如果我从虚拟机访问ec2元数据,我会看到一些用户数据。 有没有办法写它,以便cloudinit不会覆盖我设置的主机名?

编辑:

看起来像Lightsail有自己的用户数据的废弃物:

$ cat /var/lib/cloud/instances/user-data.txt #!/bin/sh echo Lightsail: Starting Instance Initialization. cat > /etc/ssh/lightsail_instance_ca.pub << EOF ssh-rsa nope EOF echo Lightsail: SSH CA Public Key created. echo >> /etc/ssh/sshd_config echo 'TrustedUserCAKeys /etc/ssh/lightsail_instance_ca.pub' >> /etc/ssh/sshd_config echo Lightsail: SSH CA Public Key registered. service sshd restart echo Lightsail: sshd restarted. #cloud-config hostname: pwnguin 

所以在cloud-init输出日志中,它抱怨hostname: command not found 。 我可以放一个shell命令来设置一个主机名,但是我可能在cloudconfig路由上运气不好。

启动实例时,可以按如下方式传递包含初始configuration(例如主机名)的用户数据:

 aws lightsail create-instances --instance-names <value> --availability-zone <value> --blueprint-id <value> --bundle-id <value> --user-data file:///full/path/to/myconfig 

myconfig文件的内容应该是:

 #cloud-config hostname: test-vm