/usr/bin/ssh-copy-id:error:no identities found in Linxu

Source: Internet
Author: User
Tags ssh

Today I saw a great God's SSH Key distribution script, in which he had a ssh-copy-id-o stricthostkeychecking=no-i ~/.ssh/id_rsa.pub root@ $ip in his shell script, and after I executed, I reported/ Usr/bin/ssh-copy-id:error:no identities found, and then on the Internet to find the next-o stricthostkeychecking=no the meaning of the original is mandatory do not check key, But Ssh-copy-id I can not use here, so in the end I can only remove-o stricthostkeychecking=no.
Original script:

The code is as follows Copy Code

#!/bin/sh
Read-p "Enter remote server IP:" IP
Ssh-copy-id-o stricthostkeychecking=no-i ~/.ssh/id_rsa.pub root@ $ip
SSH root@ $ip ' sed-i ' s/^ #RSAAuthentication yes/rsaauthentication yes/g '/etc/ssh/sshd_config '
SSH root@ $ip ' sed-i ' s/^ #PubkeyAuthentication yes/pubkeyauthentication yes/g '/etc/ssh/sshd_config '
SSH root@ $ip ' sed-i ' s/^ #PermitRootLogin yes/permitrootlogin yes/g '/etc/ssh/sshd_config '
SSH root@ $ip ' service sshd restart '
Hostname= ' ssh root@${ip} ' hostname '
echo "Add host name and IP to local/etc/hosts file"
echo "$ip $hostname" >>/etc/hosts
echo "Remote host host name is $hostname, see/etc/hosts Ensure that the hostname and IP are added to the host list file"

Modified script:

  code is as follows copy code

#!/bin/sh
Read-p" Enter remote server IP: "IP
ssh-copy-id-i ~/.ssh/id_rsa.pub $ip
ssh root@ $ip ' sed-i ' s/^ #RSAAuthentication yes/rsaauthentication yes/g '/etc/ssh/sshd_config '
ssh root@ $ip ' Sed-i "s/^ #PubkeyAuthentication yes/pubkeyauthentication yes/g"/etc/ssh/sshd_config "
ssh root@ $ip ' sed-i ' s/^# Permitrootlogin yes/permitrootlogin yes/g "/etc/ssh/sshd_config"
ssh root@ $ip ' service sshd restart '
hostname= ' SSH root@${ip} ' hostname '
Echo Add host name and IP to local/etc/hosts file
echo "$ip     $hostname" >>/etc /hosts
Echo Remote host host name is $hostname, see/etc/hosts Ensure that host name and IP are added to host list file "


In this way, we will not report/usr/bin/ssh-copy-id:error:no identities found error.

SSH Key Distribution Script
the first is to generate the SSH key script

The code is as follows Copy Code

#!/bin/sh
Ssh-keygen-t Rsa-p '-F ~/.ssh/id_rsa
CP ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

Ssh-keygen generally need to input passphrase, but generally are three return to the past, I lazy input, plus-P "" will not.


Then add the public key to the script from the node

  code is as follows copy code
#!/bin/sh
read-p" Enter remote server IP: "IP
Ssh-copy-id-o stricthostkeychecking=no- I ~/.ssh/id_rsa.pub root@ $ip
ssh root@ $ip ' sed-i s/^ #RSAAuthentication yes/rsaauthentication yes/g '/etc/ssh/sshd_ Config '
ssh root@ $ip ' sed-i ' s/^ #PubkeyAuthentication yes/pubkeyauthentication yes/g '/etc/ssh/sshd_config '
SSH root@ $ip ' sed-i ' s/^ #PermitRootLogin yes/permitrootlogin yes/g '/etc/ssh/sshd_config '
ssh root@ $ip ' service sshd Restart '
hostname= ' ssh root@${ip} ' hostname '
Echo Add host name and IP to local/etc/hosts file "
echo" $ip     $hostname ">>/etc/hosts
echo" Remote host host name is $hostname, see/etc/hosts Ensure that host name and IP are added to host list file "
Echo host Public key replication Complete"

Then the third script reads the host list and then copies the/etc/hosts to all hosts.

The code is as follows Copy Code

#!/bin/sh
cat/etc/hosts | While Read line
Todo
Ip= ' echo $LINE | awk ' {print $} ' | Grep-v "::" | Grep-v "127.0.0.1"
echo "Copying/etc/hosts to ${ip}"
Scp-o stricthostkeychecking=no/etc/hosts root@${ip}:/etc/
Done

Reference:

Http://blog.slogra.com and 51cto.com

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.