Community
Discussions | Feature Requests | Tips and Tricks
Shell script to set ssh public key in virtual machine's authorized_keys at start
#1Dec. 13, 2012 09:26:55
- Jeremy Bar
- Registered: 2011-01-05
- Posts: 30
Shell script to set ssh public key in virtual machine's authorized_keys at start
With the help of Nimbula Director in-instance attributes, an ssh public key can be injected in the virtual machine to enable password-less logins, similarly to instances in Amazon EC2.
Copy the attached script to the template of the virtual machine, and invoke it from the /etc/rc.local boot script which runs at boot time.
Then, an instance can be started with the public ssh key set with the ssh_public_key attribute, see the following launch plan for example:
Note: If vEthernets are used, the instance needs as second NIC on the flat network to have access to the attributes. A static route might be necessary to route the 192.0.0.192 traffic to the correct interface.
The script sets the ssh key of the user it is invoked as. For instance, if you have a local user named fred, you can place the following line in /etc/rc.local:
Copy the attached script to the template of the virtual machine, and invoke it from the /etc/rc.local boot script which runs at boot time.
Then, an instance can be started with the public ssh key set with the ssh_public_key attribute, see the following launch plan for example:
{
"instances": [
{
"attributes": {
"ssh_public_key": "ssh-rsa AAAAB3NzaC1....../df/UqTOMEaQ== jeremy@demo"
},
"imagelist": "/nimbula/public/lucid64-ssh-key",
"label": "ssh key instance",
"shape": "small"
}
]
}
Note: If vEthernets are used, the instance needs as second NIC on the flat network to have access to the attributes. A static route might be necessary to route the 192.0.0.192 traffic to the correct interface.
The script sets the ssh key of the user it is invoked as. For instance, if you have a local user named fred, you can place the following line in /etc/rc.local:
su - fred -c /path/to/set-authorized_keys-v2.sh &
Edited jeremy (Dec. 13, 2012 09:59:13)
Attachments:
set-authorized_keys-v2.sh (1.3 KB)