Skip to content

Instantly share code, notes, and snippets.

@gpolitis
Created February 21, 2016 05:45
Show Gist options
  • Save gpolitis/7ba1b604088511c29297 to your computer and use it in GitHub Desktop.
Save gpolitis/7ba1b604088511c29297 to your computer and use it in GitHub Desktop.
LXD utils
#!/bin/sh -e
CONTAINER=$1
lxc exec $CONTAINER -- apt-get -y install openssh-server
lxc exec $CONTAINER -- visudo
lxc exec $CONTAINER -- mkdir -p /home/ubuntu/.ssh/
lxc file push ~/.ssh/id_rsa $CONTAINER/home/ubuntu/.ssh/id_rsa
lxc file push ~/.ssh/id_rsa.pub $CONTAINER/home/ubuntu/.ssh/id_rsa.pub
lxc file push ~/.ssh/id_rsa.pub $CONTAINER/home/ubuntu/.ssh/authorized_keys
lxc exec $CONTAINER -- chown ubuntu:ubuntu /home/ubuntu/.ssh/
#!/bin/sh -e
# This script expects this input:
#
#+---------+---------+---------------------+------+-----------+-----------+
#| NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS |
#+---------+---------+---------------------+------+-----------+-----------+
#| bitlbee | RUNNING | 192.168.1.58 (eth0) | | NO | 0 |
#+---------+---------+---------------------+------+-----------+-----------+
#| firefox | RUNNING | 192.168.1.59 (eth0) | | NO | 0 |
#+---------+---------+---------------------+------+-----------+-----------+
#| mail | RUNNING | 192.168.1.56 (eth0) | | NO | 0 |
#+---------+---------+---------------------+------+-----------+-----------+
#| znc | RUNNING | 192.168.1.57 (eth0) | | NO | 0 |
#+---------+---------+---------------------+------+-----------+-----------+
CONTAINER_NAME=$1
shift
CONTAINER_IP=$(lxc list|grep $CONTAINER_NAME|awk '{split($0, a, "|"); print a[4]}'|awk '{split($0,a," "); print a[1]}')
exec ssh -X ubuntu@$CONTAINER_IP "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment