Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

ssh key passwordless using bash

I would like to use ssh key authentication. I have a file that contains:

ip location

ip location

etc

i have a bash script as follow :

 declare -A mylist
 declare -A myarray

 i=1

while read line ; do

        mylist[$i]=$(echo $line | awk '{print $1}')
        myarray[$i]=$(echo $line | awk '{print $2}')

((i++))

done <file.conf

for ip in "${mylist[@]}"; do
 for location in "${myarray[@]}" ; do

        ssh ${ip} tail -f ${location} > /home/log_${ip} 2>/dev/null &


 done

done

When i do this it asks me for password all the time.I have no idea how to generate a key can you please show me the steps.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Execute the following command from your host machine as the usual user. This will generate a public-private key for this user on that host.

ssh-keygen

The keys will by default be created under ~/.ssh and usually named as id_rsa (private key) id_rsa.pub (public key) Now the public key can be copied to any number of remote computers and all further secure log-ins to those hosts will not prompt for the password.

ssh-copy-id user@machine

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...