Simple script for SSH Key distribution

Source: Internet
Author: User

1. Two commands for generating keys and distributing public keys

Ssh-keygen-t rsa|dsa-p "Ssh-copy-id-i ~/.ssh/id_dsa.pub"-p2222 [email protected] "

2. Use expect's simple distribution script for automatic interaction

# # #shell Scripts powered by troy####!/bin/bash# #deliver pubkey# #dsa_pub_key = "/home/troy/.ssh/id_dsa.pub" [!-e $dsa _ Pub_key]&&{expect << eofset timeout-1spawn ssh-keygen-t dsa-p "expect" *save the key* "send" \ r "Expect E of; Eof}for IP in $ (awk '/^[^#]/{print $ ' all_client.txt) doport=$ (grep "^${ip}" All_client.txt|awk ' {print $} ') Expect < < Eofset timeout-1spawn ssh-copy-id-i $dsa _pub_key "-p$port [email protected] $ip" expect {"*yes/no*" {send "yes\r"; ex P_continue} "*password*" {send "tobeno.1\r"}}expect eof; Eofdone

3. Distribution of IP port configuration files

Cat All_client.txt #ip port172.16.100.104 2222172.16.100.128 2222

More usage, still learning ...
tbd!


This article is from the "top of Operations" blog, please be sure to keep this source http://trnux.blog.51cto.com/6998102/1660690

Simple script for SSH Key distribution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.