Created
          November 21, 2012 07:29 
        
      - 
      
- 
        Save mastergenius/4123591 to your computer and use it in GitHub Desktop. 
    Append ssh public key to remote servers with fabric
  
        
  
    
      This file contains hidden or 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 local, run, env, cd | |
| from fabric.contrib import files | |
| import os | |
| #env.hosts = [] | |
| PUB_KEY = "~/.ssh/id_rsa.pub" | |
| def install_public_key(pubkey_file=PUB_KEY): | |
| with open(os.path.expanduser(pubkey_file)) as fd: | |
| ssh_key = fd.readline().strip() | |
| with cd('~/'): | |
| run('mkdir -p .ssh') | |
| run('chmod 700 ~/.ssh') | |
| files.append('.ssh/authorized_keys', ssh_key) | |
| run('chmod 644 .ssh/authorized_keys') | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment