使用 bash 无密码的 ssh 密钥 [英] ssh key passwordless using bash
问题描述
我想使用 ssh 密钥认证.我有一个包含以下内容的文件:
I would like to use ssh key authentication. I have a file that contains:
ip 位置
ip 位置
等
我有一个 bash 脚本如下:
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.
推荐答案
以普通用户身份从主机执行以下命令.这将在该主机上为该用户生成一个公钥-私钥.
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
默认情况下,密钥将在 ~/.ssh 下创建,通常命名为 id_rsa(私钥) id_rsa.pub(公钥)现在可以将公钥复制到任意数量的远程计算机,并且所有进一步安全登录到这些主机都不会提示输入密码.
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
这篇关于使用 bash 无密码的 ssh 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!