实现ssh自动登录的4种方法
到B,直接键入一下指令实现ssh和scp自动登录: # sshcell # scpcell 3. 自动ssh/scp脚本 如果需要从A, 并登录: # ssh -i /root/.ssh/id_rsa_192.168.60.110 [email protected] scp也是一样的 # scp -i /root/.ssh/id_rsa_192.168.60.110 filename [email protected]:/home/someone 在文件.bashrc中加下两行,是比较麻烦的,键入: scp -P1234 filename userid@localhost: input C's password 。
那么需要ssh和scp两次,最后。
在本地用ssh命令的 -i 参数指定本地密钥,该指令需要A机器上的root用户权限, ssh-keygen 命令可以随意更改钥匙对的名字,每次做同样的操作就不用敲入这样长的命令了: alias sshcell='ssh -i /root/.ssh/id_rsa_192.168.60.110 [email protected]' alias scpcell='scp -i /root/.ssh/id_rsa_192.168.60.110 filename [email protected]:/home/someone' 这样,即在本地生成了公钥和私钥,不设置密码) # ssh [email protected] mkdir .ssh (需要输入密码) # scp ~/.ssh/id_rsa.pub [email protected]:.ssh/id_rsa.pub (需要输入密码) 在B上的命令: # touch /root/.ssh/authorized_keys (如果已经存在这个文件,中间服务器为B, 登录成功) 2. 控制n个机器如上所述自动登录 那就需要n对钥匙(密钥和公钥),目标服务器是C 从A可以ssh到B,实际上是在本机1234端口建立了一个通道) 2. 打开一个新的console, 假如ip为192.168.60.110; A和B的系统都是Linux 在A上运行命令: # ssh-keygen -t rsa (连续三次回车, 1. 自动ssh/scp方法 A为本地主机(即用于控制其他主机的机器) ; B为远程主机(即被控制的机器Server)。
从B可以ssh到C,但是A不能直接ssh到C 现在展示利用ssh通道技术从A直接传输文件到C 1. ssh -L1234:C:22 userid@B input B's password (1234是本机A的空闲端口, ssh自动登录: #!/usr/bin/expect -f set timeout 30 spawn ssh weiqiong@B expect password: send ppppppr expect ]* send ssh weiqiong@Cr expect password: send ppppppr interact scp从A拷贝文件到C: #!/usr/bin/expect -f set timeout 300 set file [lindex $argv 0] spawn scp $file weiqiong@B:/home/weiqiong expect password: send ppppppr expect ]* spawn ssh weiqiong@B expect password: send ppppppr expect ]* send scp $file weiqiong@C:/home/weiqiongr expect password: send ppppppr expect ]* exit interact scp从C拷贝文件到A: #!/usr/bin/expect -f set timeout 300 set file [lindex $argv 0] spawn ssh weiqiong@B expect password: send ppppppr expect ]* send scp weiqiong@C:/home/weiqiong/$file .r expect password: send ppppppr expect ]* send exitr expect ]* spawn scp weiqiong@B:/home/weiqiong/$file . expect password: send ppppppr interact 4. 建立ssh/scp通道 比如说我的机器是A,然后才能够到C, 比如: # ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa_192.168.60.110 这样私钥和公钥的名字分别就是: id_rsa_192.168.60.110和 id_rsa_192.168.60.110.pub;然后将 id_rsa_192.168.60.110.pub 文件的内容, 追加到sever的 ~/.ssh/authorized_keys文件中, 跳过这条) # cat /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys (将id_rsa.pub的内容追加到authorized_keys 中) 回到A机器: # ssh [email protected] (不需要密码,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/shell/11943.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
Python2爬虫入门:正则表达
时间:2021-01-11
-
python程序的两种运行方式
时间:2021-01-11
-
Python3爬虫进阶:MySQL存储
时间:2021-01-11
-
python导入模块的关键字是
时间:2021-01-11
-
python去重函数是什么
时间:2021-01-09
-
如何用python爬虫开源项目
时间:2021-01-09
-
Photoshop设计个性笔刷制作
时间:2021-01-09
-
深入理解PHP与WEB服务器交
时间:2021-01-09
热门文章
-
解析shell字段分隔符的用法(图文)
时间:2020-12-22
-
Python3爬虫进阶:MongoDB存储(非关系型数
时间:2020-12-29
-
php如何接收json数据
时间:2021-01-08
-
php ucwords函数怎么用
时间:2021-01-08
-
如何在Linux或者UNIX下调试Bash Shell脚本
时间:2020-12-22
-
python中pow什么意思
时间:2021-01-08
-
如何在python数据挖掘使用pandas包?
时间:2021-01-09
-
关于php中匿名函数与回调函数的详解
时间:2020-12-29
-
用python以字典方式写入csv文件实现操作
时间:2021-01-07
-
easyswoole 启动TableManager Cache工具的原理
时间:2021-01-08
