#!/usr/bin/env bash IP=$(lxc ls -fcsv | grep $1 | tr ' ' , | cut -d, -f3) if ! ssh -o BatchMode=yes root@$IP; then lxc exec $1 -- bash -c "mkdir -p /root/.ssh && \ echo \"$(ssh-add -L)\" \ > /root/.ssh/authorized_keys" ssh root@$IP fi