管理用户密钥比较繁琐,尤其是多密钥时候,下面给出一种方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
task "my_user", sub { my $local_keys = LOCAL{ my @key_files = qw( /root/.ssh/id_rsa.pub /home/user/.ssh/id_rsa.pub ); my @tmp; push ( @tmp, split "\n", cat $_ ) foreach @key_files; return \@tmp; }; my @remote_keys = split "\n", cat '~/.ssh/authorized_keys'; create_user "myuser", home => '/home/myuser', comment => 'My user', expire => '2100-05-30', password => 'password', system => 1, create_home => TRUE, ssh_key => join "\n", @$local_keys, @remote_keys; say connection->server; }; |
对于已经创建用户,并且远程证书文件已经存在的,追加时候直接追加用户证书
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
task "addkeys", group => "all", sub { my $local_keys = LOCAL{ my @key_files = qw( /root/.ssh/id_rsa.pub /home/user/.ssh/id_rsa.pub ); my @tmp; push ( @tmp, split "\n", cat $_ ) foreach @key_files; return \@tmp; }; my @remote_keys = split "\n", cat '~/.ssh/authorized_keys'; run 'echo @$local_keys >>/home/ZX_lz/.ssh/authorized_keys'; say connection->server; } |