您的位置:首页 > 运维架构 > Shell

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: