1.执行单一命令
[root@vps ~]# ssh user@192.168.9.243 "pwd; ls; rm -f Cent* ;echo --------; ls"
/home/user
anaconda-ks.cfg
Centos7.img
mwgt.tar.gz
--------
anaconda-ks.cfg
mwgt.tar.gz
[root@vps ~]#
2.执行本地脚本 < ssh.sh
[root@vps ~]# cat ssh.sh pwd ls touch BBBB ls
ls /root [root@vps ~]# ssh user@192.168.9.243 < ssh.sh Pseudo-terminal will not be allocated because stdin is not a terminal. /home/user anaconda-ks.cfg mwgt.tar.gz anaconda-ks.cfg BBBB mwgt.tar.gz
ls: cannot open directory /root: Permission denied
[root@vps ~]# ssh user@192.168.9.243 sudo bash -s < ssh.sh
/home/user
anaconda-ks.cfg
mwgt.tar.gz
anaconda-ks.cfg
BBBB
mwgt.tar.gz
anaconda-ks.cfg
[root@vps ~]#
3.执行带参数的命令/脚本
[root@vps ~]# cat ssh.sh echo $0 echo $1 echo $# [root@vps ~]# ssh user@192.168.9.243 'bash -s' < ssh.sh vps1 bash: vps1: command not found [root@vps ~]# ssh user@vps1 'bash -s'< ssh.sh vps1 bash vps1 1 [root@vps ~]#
PS:
[linux] ssh远程执行本地脚本 带参数的ssh传递