搭建ssh无密码远程登录的安全(ssl)shell script
2012-08-27 00:00
459 查看
#!/bin/bash
#Shell name: login_ssh.sh
#
#program:
# use key-gen to login other pc without password
#Author:pero
#Email: perofu.com@gmail.com
#
#History:
# 2012/7/21
#
#If you have any opinion please contact me
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
read -p "Please input a user name in Server that is you want to ssh:" user
read -p "Please input IP in Server that is you want to ssh:" ip
#install openssh
#if [ $user = "root" ]
#then
# echo "Don't using root to login others PC,It's dangers!!!"
# exit 77
#fi
soft=$(rpm -qa |grep openssh | wc -l)
if [ $soft -lt 3 ]
then
yum install *openssh* -y &> /dev/null
fi
#create key
ssh-keygen -t rsa
echo "Please input password to check ssh-server have [~/.ssh/authorized_keys]:"
exist=$(ssh "$user"@"$ip" 'ls -a ~/.ssh/authorized_keys' &> /dev/null )
if [ $? = "0" ]
then
echo "Please input password twice to add infomation to [~/.ssh/authorized_keys] in ssh-server:"
scp ~/.ssh/id_rsa.pub "$user"@"$ip":~/authorized_keys &> /dev/null
ssh "$user"@"$ip" 'cat ~/authorized_keys >> ~/.ssh/authorized_keys; rm -rf ~/authorized_keys'
else
echo "Please input password twice to add infomation to [~/.ssh/authorized_keys] in ssh-server:"
ssh "$user"@"$ip" 'mkdir -p ~/.ssh/'
scp ~/.ssh/id_rsa.pub "$user"@"$ip":~/.ssh/authorized_keys &> /dev/null
fi
#Shell name: login_ssh.sh
#
#program:
# use key-gen to login other pc without password
#Author:pero
#Email: perofu.com@gmail.com
#
#History:
# 2012/7/21
#
#If you have any opinion please contact me
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH
read -p "Please input a user name in Server that is you want to ssh:" user
read -p "Please input IP in Server that is you want to ssh:" ip
#install openssh
#if [ $user = "root" ]
#then
# echo "Don't using root to login others PC,It's dangers!!!"
# exit 77
#fi
soft=$(rpm -qa |grep openssh | wc -l)
if [ $soft -lt 3 ]
then
yum install *openssh* -y &> /dev/null
fi
#create key
ssh-keygen -t rsa
echo "Please input password to check ssh-server have [~/.ssh/authorized_keys]:"
exist=$(ssh "$user"@"$ip" 'ls -a ~/.ssh/authorized_keys' &> /dev/null )
if [ $? = "0" ]
then
echo "Please input password twice to add infomation to [~/.ssh/authorized_keys] in ssh-server:"
scp ~/.ssh/id_rsa.pub "$user"@"$ip":~/authorized_keys &> /dev/null
ssh "$user"@"$ip" 'cat ~/authorized_keys >> ~/.ssh/authorized_keys; rm -rf ~/authorized_keys'
else
echo "Please input password twice to add infomation to [~/.ssh/authorized_keys] in ssh-server:"
ssh "$user"@"$ip" 'mkdir -p ~/.ssh/'
scp ~/.ssh/id_rsa.pub "$user"@"$ip":~/.ssh/authorized_keys &> /dev/null
fi
相关文章推荐
- Centos设置SSH免密码远程登录
- Linux下通过 ssh-copy-id 无密码远程登录主机
- Git服务器搭建及SSH无密码登录设置
- Mac下使用iTerm2让SSH免密码登录远程服务器
- 详解ssh通过公钥密码、免密码登录以及导入公钥文件三种形式实现远程登录
- SSH无密码登录远程主机(cygwin --> Ubuntu)
- 在freeBSD服务器之间搭建ssh无密码登录
- SSH免密码远程登录Linux
- 01、从零搭建CentOS集群免密码SSH登录
- Git服务器搭建及SSH无密码登录设置
- MAC便捷ssh直接登录远程服务器(免输密码)
- Linux/CentOS启动SSH远程登录无密码
- ssh登录远程主机免输密码
- linux远程登录ssh免密码
- ssh无密码远程登录失败终极解决方案
- SSH用私钥登录远程服务器时提示私钥不安全
- Linux配置远程SSH无密码登录
- ssh 使用公钥免密码远程登录
- 在freeBSD服务器之间搭建ssh无密码登录
- ssh 实现linux/unix无密码远程登录