首页 > 其他 > 详细

编写快速登陆服务器的脚本

时间:2019-03-21 11:31:08      阅读:151      评论:0      收藏:0      [点我收藏+]

                编写快速登陆服务器的脚本

                                      作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

 

 

 

一.便携脚本

1>.安装依赖包

技术分享图片
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# yum -y install sshpass
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                                        | 3.6 kB  00:00:00     
extras                                                                                                                                                                                      | 3.4 kB  00:00:00     
updates                                                                                                                                                                                     | 3.4 kB  00:00:00     
(1/2): extras/7/x86_64/primary_db                                                                                                                                                           | 187 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                                                                                                          | 3.3 MB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================================================================================
 Package                                           Arch                                             Version                                                 Repository                                        Size
===================================================================================================================================================================================================================
Installing:
 sshpass                                           x86_64                                           1.06-2.el7                                              extras                                            21 k

Transaction Summary
===================================================================================================================================================================================================================
Install  1 Package

Total download size: 21 k
Installed size: 38 k
Downloading packages:
sshpass-1.06-2.el7.x86_64.rpm                                                                                                                                                               |  21 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : sshpass-1.06-2.el7.x86_64                                                                                                                                                                       1/1 
  Verifying  : sshpass-1.06-2.el7.x86_64                                                                                                                                                                       1/1 

Installed:
  sshpass.x86_64 0:1.06-2.el7                                                                                                                                                                                      

Complete!
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# yum -y install sshpass

2>.便携脚本

技术分享图片
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /usr/local/bin/clientServer.sh 
#!/bin/bash
#@author :yinzhengjie
#blog:http://www.cnblogs.com/yinzhengjie
#EMAIL:y1053419035@qq.com

host=$1
passwd="yinzhengjie"

sshpass  -p ${passwd} ssh root@${host} -o StrictHostKeyChecking=no
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /usr/local/bin/clientServer.sh
技术分享图片
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /usr/local/bin/clientServer.sh      
-rw-r--r--. 1 root root 199 Mar 21 11:11 /usr/local/bin/clientServer.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chmod +x /usr/local/bin/clientServer.sh 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# ll /usr/local/bin/clientServer.sh      
-rwxr-xr-x. 1 root root 199 Mar 21 11:11 /usr/local/bin/clientServer.sh
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# chmod +x /usr/local/bin/clientServer.sh

3>.测试脚本

技术分享图片
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/hosts | grep yinzhengjie
172.30.1.101 node101.yinzhengjie.org.cn
172.30.1.102 node102.yinzhengjie.org.cn
172.30.1.103 node103.yinzhengjie.org.cn
172.30.1.104 node104.yinzhengjie.org.cn
172.30.1.105 node105.yinzhengjie.org.cn
172.30.1.106 node106.yinzhengjie.org.cn
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# cat /etc/hosts | grep yinzhengjie
技术分享图片
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# clientServer.sh node102.yinzhengjie.org.cn
Last login: Thu Mar 21 11:07:53 2019 from 172.30.1.101
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# who
root     pts/0        2019-03-21 11:13 (172.30.1.101)
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# 
[root@node102.yinzhengjie.org.cn ~]# exit 
logout
Connection to node102.yinzhengjie.org.cn closed.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# clientServer.sh node102.yinzhengjie.org.cn
技术分享图片
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# clientServer.sh node103.yinzhengjie.org.cn
Last login: Tue Mar 19 13:50:35 2019 from 172.30.1.2
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# who
root     pts/0        2019-03-21 11:13 (172.30.1.101)
[root@node103.yinzhengjie.org.cn ~]# 
[root@node103.yinzhengjie.org.cn ~]# exit 
logout
Connection to node103.yinzhengjie.org.cn closed.
[root@node101.yinzhengjie.org.cn ~]# 
[root@node101.yinzhengjie.org.cn ~]# clientServer.sh node103.yinzhengjie.org.cn

 

 

 

二.为脚本加密

  上面我们通过脚本的确是可以远程登陆服务器,细心的小伙伴会发现以上脚本很缺乏安全感,就是密码是都一样才可以使用该脚本!而且在文件中编写脚本的话密码是明文方式保存,稍微会点Linux的人看到后可能会做坏事!因此,我们需要对脚本进行加密操作,这样别人拿到后就没法看到脚本的真实内容啦~

1>.加密脚本

 

2>.测试加密后的脚本

 

3>.解密脚本

 

编写快速登陆服务器的脚本

原文:https://www.cnblogs.com/yinzhengjie/p/10570254.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!