Created
November 26, 2013 02:20
-
-
Save mather/7652534 to your computer and use it in GitHub Desktop.
fabricで鍵認証をセットする ref: http://qiita.com/mather314/items/d8db37ab6aaaaccdabba
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fabric.api import * | |
@task | |
def copy_id(file="~/.ssh/id_rsa.pub"): | |
"""Identityをauthorized_keysに追加する""" | |
put(file, "/tmp/id.pub") | |
try: | |
run("if [ ! -d ~/.ssh ]; then mkdir -p ~/.ssh; fi") | |
run("if [ ! -f ~/.ssh/authorized_keys ]; then cp /tmp/id.pub ~/.ssh/authorized_keys && chmod 0600 ~/.ssh/authorized_keys; fi") | |
run("cat ~/.ssh/authorized_keys /tmp/id.pub | sort -u > /tmp/uniq.authorized_keys") | |
run("if [ `cat ~/.ssh/authorized_keys | wc -l` -lt `cat /tmp/uniq.authorized_keys | wc -l` ]; then cat /tmp/id.pub >> ~/.ssh/authorized_keys; fi") | |
finally: | |
run("rm -f /tmp/id.pub /tmp/uniq.authorized_keys") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fab -H target copy_id:file=~/.ssh/custom_id.pub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment