expect实现ssh自动登录

mac上安装expect实现ssh自动登录 必备软件 tcl或https://download.csdn.net/download/hbj206/12080241 expect或:https://download.csdn.net/download/hbj206/12080247 下载软件的地址建议使用浏览器直接下载,下载的文件为*.tar文件,使用下载软件下载的*.tar.gz可能会出现问题。 下载后的*.ta... 阅读详情

每次登陆服务器,都要输入账户密码,一般我们可以配置免密登陆。比如:将本地id_rsa.pub文件的内容,配置到远程服务器的~/.ssh/authorized_keys文件,具体的步骤可以参考网上其他教程。

但是有时候由于一些限制要求,不能配置免密登陆,每次使用ssh username@hostIp再输入密码的方式太耗时,想要进行密码自动填充。

懒是一种生产力。

解决方法:使用expect在ssh_login.sh脚本中封装expect的ssh登录自动填充密码功能。

需要安装的软件:

  1. Mac安装expect:brew install expect
  2. LUIT

    平时在工作中经常连接Linux/Unix服务器,有的服务器是UTF-8,有的服务器是GBK。在Windows下SecureCRT可以完美解决这个问题,在Mac下要通过修改配置进行切换,比较麻烦。
    下面隆重介绍一款Terminal下输出转码的工具——LUIT支持Mac、Linux原生的Terminal。
      •  下载地址
            http://invisible-island.net/luit/luit.html#download 
      •  解压
            tar zxvf luit.tar.gz
            cd luit-20141204  //可能版本会不一样
      •  配置
            ./configure
      •  编译
            make
      •  安装
            make install
      •  卸载
            make uninstall
      •  使用
            luit -encoding gbk ssh user@host

脚本:
起个名字:ssh_login.sh

#!/usr/bin/expect
set host [lindex $argv 0 ]
if {$host != ""} {
    spawn luit -encoding gbk ssh admin@${host}
    expect {
        "(yes/no)?" {
            send "yes\n"
            expect "password:" {send "密码\n"}
        }
        "password:" {send "密码\n"}


    }
    interact
} else {
    puts stdout "Please enter the target host.";
}

完成上面的步骤之后,就可以在ssh_login.sh的目录下执行:./ssh_login.sh hostIp,登录服务器了。

如果安装了iterm2,可以再~/.zshrc中配置alias login='~/你的目录路径/ssh_login.sh',之后就可以在任何地方,通过login hostIp登录了。


参考资料:
网络资料
备注:
转载请注明出处:http://blog.csdn.net/wsyw126/article/details/80140079
作者:WSYW126

利用expect脚本在iTerm2中实现SSH自动登录 本文详细介绍了如何在MacOS的iTerm2终端中,利用expect脚本实现SSH自动登录,以解决开发者日常重复输入密码的效率痛点。文章涵盖从安装expect工具、编写参数化脚本,到在iTerm2中配置安全快捷方式的完整流程,并提供了处理复杂登录场景与安全存储密码的进阶技巧。 阅读详情

相关推荐

【shell笔记】-----shell脚本使用 expect指令实现ssh自动登录

运用到虚拟机的时候,经常需要ssh root@192.168.1.1或者直接ssh 192.168.1.1,然后等待输入用户密码。这样下来,对于服务器运维每天要登录很多服务器,那么这一步骤就显得累赘。在学习网络中,用SecureCRT Application登录router/switch是很方便的,只需要将登录信息记录下来,下次即可直接登录。 在Linux中expect就是一个处理交互的指令...

weixin_42611900的博客 4695

linux ssh expect,linux命令expect实现ssh登陆

SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。那么你知道linux命令expect实现ssh登陆么?接下来是小编为大家收集的linux命令expect实现ssh登陆,欢迎大家阅读:linux命令expect实现ssh登陆1 expect可用于自动化脚本的书写yum -y install expect即可下载2 脚本...

weixin_31542609的博客 2864

Kettle下载与安装教程【保姆版】

Kettle简介 Kettle最早是一个开源的ETL工具,全称为KDE Extraction, Transportation, Transformation and Loading Environment。后来Kettle重命名为Pentaho Data Integration 。 它由Java开发,支持跨平台运行,其特性包括:支持100%无编码、拖拽方式开发ETL数据管道;可对接包括传统数据库、文件、大数据平台、接口、流数据等数据源;支持ETL数据管道加入机器学习算法。 主要功能 Pentaho D

weixin_43407520的博客 12万+

shell从入门到精通(33)expect脚本使用ssh遍历配置文件进行远程登录执行命令

参数说明: set:可以设置超时,也可以设置变量 timeout:expect超时等待时间,默认10S spawn:执行一个命令 expect “”:匹配输出的内容 exp_continue:继续执行下面匹配 \r:可以理解为回车 $argc:统计位置参数数量 [lindex argv0]:脚本后第一个参数,类似于shell中argv0]:脚本后第一个参数,类似于shell中1,以此类推 puts:打印字符串,类似于echo awk -v I="$ip":赋值变量 expect{…}:输入多行记录 其他

二进制君 2651

别再死记硬背了!用Amesim HCD库亲手搭建单向阀、锥阀、球阀模型(附详细参数设置)

本文详细介绍了如何使用Amesim HCD库从零构建单向阀、锥阀和球阀的仿真模型,帮助工程师摆脱死记硬背,掌握物理建模的核心技巧。通过实战案例和参数设置指南,读者将学会如何优化阀门动态响应、验证流量特性以及处理旋转运动等独特挑战,提升液压系统设计效率。

weixin_29248611的博客 516

sentaurus学习笔记(HFET_pGate_GaN仿真)(九)

`(sdedr:define-constant-profile-placement "Ohmic.s" "Ohmic" "Pl.ohmic.s" 0.002)`这一行将`"Ohmic"`掺杂剖面放置在`"Pl.ohmic.s"`参考评估窗口中,同样`0.002`可能表示掺杂剖面在窗口中的偏移量或其他参数。欧姆接触是半导体器件中的一种低阻抗电气接触,通常需要高掺杂来减少接触电阻并提高器件性能。通过这些步骤,SDE能够为器件的源极和漏极区域设置高掺杂的欧姆接触,这对于确保器件的高性能和低接触电阻至关重要。

qq_52640792的博客 1389

Expect远程ssh登录主机执行命令

命令连接到远程服务器上的SSH端口,并输入用户名和密码。接下来,脚本等待远程服务器的输出并根据输出执行相应的操作,例如,如果服务器请求你接受新的ssh指纹,脚本会自动接受它,继续等待。使用Expect可以自动化执行多种复杂交互式任务,例如,你可以使用Expect编写脚本来自动登录到FTP服务器并上传文件,或者连接到数据库服务器并执行查询。Expect是一个命令行工具,它可以自动化交互式任务(如SSH登录、FTP传输等)。Expect通过模拟用户输入,识别应用程序输出,实现自动化交互式任务的自动化。

不积跬步,无以至千里;不积小流,无以成江海。 1680

从科研小白到动物行为分析:我的DeepLabCut 3.0安装与初体验全记录

本文记录了从科研小白到成功安装并使用DeepLabCut 3.0进行动物行为分析的全过程。详细介绍了Anaconda环境配置、CUDA版本选择、DeepLabCut安装步骤及验证方法,并分享了初体验中的实用技巧和跨学科研究心得,为生物研究者提供了AI工具应用的实战指南。

weixin_30235225的博客 407

【环境配置】expect实现ssh自动登陆+转发端口

Linux学习记录——expect实现ssh自动登陆+转发端口

qq_42775328的博客 1993

欧姆龙PMAC CK3M控制器新手避坑指南:从开箱到EtherCAT总线配置的完整流程

本文详细介绍了欧姆龙PMAC CK3M控制器的完整配置流程,从开箱检查到EtherCAT总线配置,特别针对新手常见问题提供避坑指南。内容包括硬件连接、软件安装、EtherCAT主站初始化、从站配置、电机参数设置等关键步骤,帮助工程师快速掌握PMAC控制器的使用技巧。

weixin_42532938的博客 395

Ubuntu 解决WPS缺少宋体,微软雅黑等中文字体

这篇博客解决Ubuntu 18.04 无法使用中文字体的问题 问题描述

分享日常的学习,开展的项目,编写的软件,解决的问题等~ 1万+

expect自动登录ssh,ftp

exp_continue} //第一次ssh连接会提示yes/no,继续。shell功能很强大,但是不能实现有交互功能的多机器之前的操作,例如ssh和ftp.而expect可以帮助我们来实现."*password:" { send "$password\r" } //出现密码提示,发送密码。1、根据不同IP和密码ssh自动连接到不同的服务器,并停在登录服务器上。//交互模式,用户会停留在远程服务器上面.//接收第一个参数,并设置IP。

beck_li的博客 1204

Office 365中的Assigned Access详细功能介绍

本文系统介绍了Office365中AssignedAccess功能的应用与管理。作为Windows系统的重要安全特性,AssignedAccess可将设备锁定为单应用模式,有效防范未授权访问。文章详细阐述了其核心功能、技术架构及配置方法,包括UWP/Win32应用支持、多用户配置、与AzureAD集成等。通过MicrosoftEndpointManager可实现批量部署和远程监控,适用于公共终端、零售设备等场景。该功能为企业数字化转型提供了安全、可控的终端管理方案,在保障数据安全的同时优化用户体验。

xueyunshengling的博客 231

expect实现scp ssh自动输入密码登录

expect是一种自动交互语言,能实现在shell脚本中为scp和ssh等自动输入密码自动登录。 下面给出scp和ssh的使用示例: 1、scp expect -c " spawn scp root@1.2.3.4:/root/1.log /root expect { \"*assword\" {set timeout 300; send \"password\r\";} \"yes/no\" {send \"yes\r\"; exp_continue;} } expe

hefy780144的博客 5072

2025届程序技术类笔试题

希尔排序在直接插入排序的基础上进行了改进,它通过比较相距一定间隔的元素来进行,各轮比较所用的距离随着算法的进行而减小,直到只比较相邻元素的最后一轮排序为止。某人逆着水流的方向向岸边划船,每次行进前进x米后需要休息一下,休息期间船会自行倒退y米,每次休息后再次行进,前进距离缩短1/5,若起始距离岸边为m米,问:能否到达岸上,需要行进多少次才能上岸。直接插入排序的原理是将第i个元素插入前面i-1个已排好序的记录中,将比第i个元素大的记录依次向后移动一个位置,将第i个元素插入空位。第二轮相邻比较,后移2次。

博客 601

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

Linux下用expect实现ssh自动登录并执行脚本

Linux下用expect实现ssh自动登录并执行脚本   expect不是系统自带的,需要安装:         yum install expect 装完后才可执行以下脚本。    ssh密码认证的登陆脚本: Shell代码  #!/bin/bash      # 匹配提示符   CMD_PROMPT="\](\$|#)"  

莫名的拉风的博客 1万+

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

利用expect实现SSH登录密码的自动填充

SSH可以远程登录另一台主机:基本使用口令如下 1.ssh user@host address  如:ssh ysaicll@192.168.0.1    以ysaicll身份登录主机192.168.0.1 2.ssh host address  如:ssh 192.168.0.1    直接登录主机192.168.0.1,适用于用户名和本地一致情况 3.ssh -p 222 user@

一勺池里争高低 893

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

iTerm 2 使用触发器和 expect 实现 ssh 自动登录

前言对于 YAML 工程师来说,我们经常需要 ssh 登录不同的服务器,每次登录时都要经历两个步骤:输入ssh root@host-ip输入密码每次都重复这样的操作,不仅麻烦,还要记忆...

程序猿DD 1449

expect 实现ssh自动登录执行command

#!/usr/bin/expect set ip [lindex $argv 0] set username [lindex $argv 1] set password [lindex $argv 2] set shell [lindex $argv 3] spawn ssh $username@$ip $shell; expect { "(yes/no)?" { send "yes\r"; expect "*password:"; send "$password\r"; .

火云邪神的博客 297

使用expect脚本实现ssh自动登录

在shell脚本编程中,经常会有远程执行命令的需求,而要做到这一点,一种方法是使用ssh建立起主机间的信任关系,而另一种方法是使用交互式的语言自动输入密码,下面就使用expect脚本实现ssh自动登录的功能。 #!/usr/bin/expect -f # 设置变量 set password [lindex $argv 0] set ipaddr [lrange $argv 1] se...

云的后端 267

expect命令实现ssh自动登录

#!/usr/bin/expect set USER [lindex $argv 0] set IP [lindex $argv 1] set PASSWD [lindex $argv 2] spawn ssh $USER@$IP expect { "*yes/no*" { send "yes\r" } "*password:" { send "$PASSWD\r"...

hzp 328
上一篇: XML文档中的xmlns、xmlns:xsi和xsi:schemaLocation
下一篇: Java中的线程池——ThreadPoolExecutor源代码分析
WSYW126
博客等级 码龄11年 115粉丝 178原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值