python脚本复制ssh公钥文件到其他服务器,,如下脚本复制ssh公钥文
python脚本复制ssh公钥文件到其他服务器,,如下脚本复制ssh公钥文
如下脚本复制ssh公钥文件到其他服务器,使用了 http://www.lag.net/paramiko/ 模块:
#!/usr/bin/pythonimport osfrom getpass import getpassimport paramikodef deploy_key(key, server, username, password): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(server, username=username, password=password) client.exec_command('mkdir -p ~/.ssh/') client.exec_command('echo "%s" > ~/.ssh/authorized_keys' % key) client.exec_command('chmod 644 ~/.ssh/authorized_keys') client.exec_command('chmod 700 ~/.ssh/')key = open(os.path.expanduser('~/.ssh/id_rsa.pub')).read()username = os.getlogin()password = getpass()hosts = ["hostname1", "hostname2", "hostname3"]for host in hosts: deploy_key(key, host, username, password)
相关内容
- python + supervisor + uwsgi 跑web程序出现cpu 100%问题解决,
- python 脚本获得当前用户,python当前用户,import osimp
- linux系统下查看文件或目录的用户/组信息,linux,linux系
- Python 调用 C++,python调用,换句话说,就是需要把C+
- 安装windows10之后pycharm启动80端口上的web应用报错:CRI
- java中执行python脚本工具类,需要jython.jar,pythonjython.
- python datetime和unix时间戳之间相互转换,pythondatetime,py
- python webpy bad argument to internal function,webpyargument,使用
- python urllib2 timeout处理实例,pythonurllib2,python的urlli
- python循环中的break continue使用,pythonbreak,count = 0whi
评论关闭