码迷,mamicode.com
首页 > 系统相关 > 详细

实现ssh无密码登录 shell脚本

时间:2015-05-23 10:03:33      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:shell   ssh   bash   密码   

默认远程主机上已经存在 ~/.ssh 目录。在自己PC上执行下面脚本,输入服务器用户名和ip地址,下次登录可实现无密码登录。

#!/bin/bash
id_res_pub=~/.ssh/id_rsa.pub
if [ ! -f "$id_res_pub" ];then
    ssh-keygen -t rsa
else
    echo "id_rsa.pub is exist!"
fi
echo
echo "Enter remote host user name"
read rname
echo
echo "Enter remote host ip address"
read ip_address
echo
echo "You remote host :"
echo "${rname}@${ip_address}"

cat .ssh/id_rsa.pub | ssh ${rname}@${ip_address} 'cat >> .ssh/authorized_keys'


实现ssh无密码登录 shell脚本

标签:shell   ssh   bash   密码   

原文地址:http://blog.csdn.net/hanglinux/article/details/45932355

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!