shell脚本 --- expect ssh scp 命令学习
2017-05-03 08:22
441 查看
准备:使用安装两个虚拟机。安装ssh。如果是ubuntu的可能会出现安装失败的情况,首先用apt-get install openssh-client=提示版本回退ssh,然后用apt-get install ssh安装。
安装完可能无法用root用户登录,修改配置文具/etc/ssh/sshd_config 中的PermitRootLogin without-password 为 PermitRootLogin yes。然后使用service ssh restart 重启ssh服务即可。
1.expect
#!/usr/bin/expect
spawn ssh localhost //远程登录
expect "root@localhost's password:" //如果是root@localhost's password:
send 123 //发送密码
2.ssh
ssh 【可选参数】 用户名@IP 命令
这样就可以远程调用命令例如:
ssh root@192.168.58.128 'ls /home/;df -h' 远程显示home目录,并显示磁盘使用情况。命令间用;隔开
3.scp
scp 文具名 用户名@ip:目标路径
例如:
scp ubuntu2 root@192.168.58.128:/home/ubuntu2
安装完可能无法用root用户登录,修改配置文具/etc/ssh/sshd_config 中的PermitRootLogin without-password 为 PermitRootLogin yes。然后使用service ssh restart 重启ssh服务即可。
1.expect
#!/usr/bin/expect
spawn ssh localhost //远程登录
expect "root@localhost's password:" //如果是root@localhost's password:
send 123 //发送密码
2.ssh
ssh 【可选参数】 用户名@IP 命令
这样就可以远程调用命令例如:
ssh root@192.168.58.128 'ls /home/;df -h' 远程显示home目录,并显示磁盘使用情况。命令间用;隔开
3.scp
scp 文具名 用户名@ip:目标路径
例如:
scp ubuntu2 root@192.168.58.128:/home/ubuntu2
相关文章推荐
- Shell脚本学习之expect命令
- Shell脚本学习之expect命令
- ssh,expect脚本实现远程登录,拷贝命令scp,rsync服务器的搭建
- 使用expect实现shell脚本中scp,ssh自动输入口令
- Shell脚本学习之expect命令
- Shell脚本学习之expect命令
- Shell脚本学习之expect命令
- Shell脚本学习之expect命令
- Shell脚本学习之expect命令
- Shell脚本学习(三):shell 函数和一些常用符号和命令
- 脚本不输密码执行scp命令(需要expect和send命令)
- 在shell脚本中用expect 实现 scp 文件的时候不手动输入密码
- shell结合expect写的批量scp脚本工具
- 使用expect和ssh远程执行命令的脚本
- 在shell脚本中用expect 实现 scp 文件的时候不手动输入密码
- shell技巧--ssh远程执行包含nohup命令的脚本
- shell结合expect写的批量scp脚本工具
- 通过在shell脚本中用expect实现远程scp文件
- 最简单的非交互ssh远程执行命令expect脚本
- Shell脚本学习——[命令之乐]