Linux信任登录,免密码登录的脚本:

需要安装expect,可以yum也可以编译安装,编译后注意脚本中的expect路径。

rsa.exp

#!/usr/bin/expect
##################################################
# #
# Author: #
# Date: -- #
# Descrition: SSH auto create rsa key at local #
# #
################################################## # Get parameter
set dbip [lindex $argv ]
set pass [lindex $argv ] # create local rsa key
spawn ssh-keygen -t rsa;
expect "*(/root/.ssh/id_rsa):";
send "\r";
expect "*(empty for no passphrase):";
send "\r";
expect "*Enter same passphrase again:";
send "\r";
expect eof

pubKey.exp

#!/usr/bin/expect
##################################################
# #
# Author: #
# Date: -- #
# Descrition: SSH auto add accredit to server #
# #
################################################## # Get parameter
set dbip [lindex $argv ]
set pass [lindex $argv ]
set timeout # create .ssh dir
spawn ssh root@$dbip
expect {
"yes/no" { send "yes\r"; exp_continue}
"password:" {
send "$pass\r";
expect {
"Last login" {
send "mkdir -p /root/.ssh \r";
send "chmod 700 /root/.ssh \r"
}
}
}
"Last login" { exit }
}
expect "" # scp rsa key to remote server
spawn scp /root/.ssh/id_rsa.pub root@$dbip:/root/.ssh/id_rsa.pub.tmp;
expect "*password:";
send "$pass\r";
expect eof spawn ssh root@$dbip cat /root/.ssh/id_rsa.pub.tmp >> /root/.ssh/authorized_keys
expect "*password:";
send "$pass\r";
expect eof spawn ssh root@$dbip rm -f /root/.ssh/id_rsa.pub.tmp

在登录时系统提示信息,例如提示:

Address 10.1.1.1 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

可以通过修改sshd配置取消输出,以免影响自动化部署脚本允许:

[root@zabbix ~]# sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config ; service sshd restart

【Linux】自动化部署可信任登录的更多相关文章

  1. Linux自动化部署尝试

    Linux自动化部署尝试   最近做一个项目临近测试,购买的是阿里云的服务器,每次部署都是手动打包war,然后上传到服务器,然后修改配置文件,不仅繁琐,而且费时,就思索着找一个一键式的部署方式,今天终 ...

  2. Linux 自动化部署DNS服务器

    Linux 自动化部署DNS服务器 1.首先配置主DNS服务器的IP地址,DNS地址一个写主dns的IP地址,一个写从dns的地址,这里也可以不写,在测试的时候在/etc/resolv.conf中添加 ...

  3. Linux 自动化部署Rsyslog服务

    Linux 自动化部署Rsyslog服务 源码如下: #/bin/bash #该脚本用于自动化部署Ryslog服务配置 #作者:雨中落叶 #博客:https://www.cnblogs.com/yuz ...

  4. Linux 自动化部署

    1.pexpect Pexpect 是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Py ...

  5. 一次Linux自动化部署尝试

    最近做一个项目临近测试,购买的是阿里云的服务器,每次部署都是手动打包war,然后上传到服务器,然后修改配置文件,不仅繁琐,而且费时,就思索着找一个一键式的部署方式,今天终于腾出时间来做这件事,记录一下 ...

  6. ezdpl Linux自动化部署实战

    最近把ezdpl在生产环境中实施了,再加上这段时间的一些修改,一并介绍一下. 再次申明: ezdpl不是开箱即用的,需要根据自己的应用环境定制.对初学者来说使用起来反倒困难更多.风险更大. 它不是一个 ...

  7. Shell 自动化部署免密登录

    1 .配置主机名称 参考:Linux 修改主机名 和 ip 映射关系 2 . 编写脚本 root.sh 内容 #!/bin/bash SERVERS="hadoop0 hadoop1 had ...

  8. Kickstart + http Linux自动化部署服务端

    设备需要开启Network Boot功能.具体PXE技术就另外提,本文主要讲解配置. 在搭建该服务器之前需要关闭SELinux和iptables不然可能dhcp服务都起不来,客户端收不到IP地址,无法 ...

  9. jenkins+springboot+svn linux 自动化部署

    需要下载 publish over ssh 插件(远程上传项目到服务器) Maven Integration plugin 插件(构建maven项目) 然后将各种配置配置好 最终项目在服务器上的路径是 ...

随机推荐

  1. JAVA 流式布局管理器

    //流式布局管理器 import java.awt.*; import javax.swing.*; public class Jiemian2 extends JFrame{ //定义组件 JBut ...

  2. Struts2 Annotation 注解配置

    也叫Zero Configuration(零配置),它省去了写xml文件的麻烦,可以直接在类叫进行配置,不用在java文件和xml文件中来回切换. 必须导入struts2-convention-plu ...

  3. MYSQL中replace into的用法以及与inset into的区别

    在向表中插入数据时,我们经常会遇到这样的情况:1.首先判断数据是否存在:2.如果不存在,则插入:3.如果存在,则更新. 在SQL Server中可以这样处理: if not exists (selec ...

  4. android之location01

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <Linear ...

  5. Move Zeroes

    https://leetcode.com/problems/move-zeroes/ Given an array nums, write a function to move all 0's to ...

  6. java程序内存使用

    一.内存使用示意图 二.java运行时数据区域 1.程序计数器: 当前线程所执行字节码的行号提示器. 2.java虚拟机栈: 线程私有,与线程生命周期相同,保存基本数据类型,如果线程所请求的栈深度大于 ...

  7. [Flex] ButtonBar系列——简单布局

    <?xml version="1.0" encoding="utf-8"?> <!--通过layout属性,设置ButtonBar布局--&g ...

  8. Servlet中读取参数的几种方式

    为每一Servlet设置初始化参数 可以为每一个Servlet在对应的web.xml中的Servlet节点下编写初始化参数,格式如下: <init-param> <param-nam ...

  9. JAVA中集合类的使用

    总的说来常用的集合类有两大类:Collection 和 Map 1) Collection接口有List和Set两大类子接口,List有ArrayList.LinkedList.Vector子类,Se ...

  10. flexbox弹性盒模型

    div { display:flex; } div a{ }