ssh客户端配置管理器
ssh-config的Python项目详细描述
ssh配置
ssh客户端配置文件管理器
什么是ssh_配置?
https://linux.die.net/man/5/ssh_config
为什么
我不记得我管理的所有服务器。同时,所有服务器都需要所有不同的配置来连接到它。我知道~.ssh/config可以处理这种问题。我想让它更容易处理这个文件。
是的,我不确定这是一种处理它的方法。但我在努力。
要求
Python2.7、3.6、3.7
安装
$ pip install ssh-config
用法
ssh-config 0.0.12
Usage:
ssh-config [options] [COMMAND] [ARGS...]
Options:
-h --help Show this screen.
-v --version Show version.
-f --config FILE Specify an ssh client file [default: ~/.ssh/config]
Commands:
ls Show list of Hosts in client file
add Add new Host configuration
rm Remove exist Host configuration
init Create ~/.ssh/config file
import Import Hosts from csv file to SSH Client config
export Export Hosts to csv format
bastion Bastion register/use
version Show version information
用例
列出主机
$ ssh-config ls
# It shows name and HostName attribute
server1: 203.0.113.76
*: None
server_cmd_1: 203.0.113.76
server_cmd_2: 203.0.113.76
server_cmd_3: 203.0.113.76
添加主机
$ ssh-config add "server_cmd_4" HostName=203.0.113.77 IdentityFile="~/.ssh/cmd_id_rsa"
更新主机
$ ssh-config add --update -p "server_cmd_3" IdentityFile="~/.ssh/cmd_id_rsa"
移除主机
$ ssh-config rm "server_3"
使用模式获取列表或更新存在主机< EH3>列出具有模式的主机
$ ssh-config ls "server_*"
# It shows name and HostName attribute
server_cmd_1: 203.0.113.76
server_cmd_2: 203.0.113.76
server_cmd_3: 203.0.113.76
使用模式更新主机
$ ssh-config add --update -p "server_*" IdentityFile="~/.ssh/cmd_id_rsa"
向多个服务器添加ssh密钥
ssh-config ls --only-name | xargs -I{} ssh-copy-id -i ~/.ssh/id_rsa {}
$ ssh-config ls
# It shows name and HostName attribute
server1: 203.0.113.76
*: None
server_cmd_1: 203.0.113.76
server_cmd_2: 203.0.113.76
server_cmd_3: 203.0.113.76
$ ssh-config add "server_cmd_4" HostName=203.0.113.77 IdentityFile="~/.ssh/cmd_id_rsa"
$ ssh-config add --update -p "server_cmd_3" IdentityFile="~/.ssh/cmd_id_rsa"
$ ssh-config rm "server_3"
列出具有模式的主机
$ ssh-config ls "server_*"
# It shows name and HostName attribute
server_cmd_1: 203.0.113.76
server_cmd_2: 203.0.113.76
server_cmd_3: 203.0.113.76
使用模式更新主机
$ ssh-config add --update -p "server_*" IdentityFile="~/.ssh/cmd_id_rsa"
向多个服务器添加ssh密钥
ssh-config ls --only-name | xargs -I{} ssh-copy-id -i ~/.ssh/id_rsa {}
$ ssh-config ls "server_*"
# It shows name and HostName attribute
server_cmd_1: 203.0.113.76
server_cmd_2: 203.0.113.76
server_cmd_3: 203.0.113.76
$ ssh-config add --update -p "server_*" IdentityFile="~/.ssh/cmd_id_rsa"
向多个服务器添加ssh密钥
ssh-config ls --only-name | xargs -I{} ssh-copy-id -i ~/.ssh/id_rsa {}