说明:能够作SSH免密登陆以后执行,这样能够省去每次执行输入密码的提示。html
对于简单的命令:bash
若是是简单执行几个命令,则:服务器
ssh user@remoteNode "cd /home ; ls"
基本能完成经常使用的对于远程节点的管理了,几个注意的点:ssh
对于脚本的方式:spa
有些远程执行的命令内容较多,单一命令没法完成,考虑脚本方式实现:code
#!/bin/bash ssh user@remoteNode > /dev/null 2>&1 << eeooff cd /home touch abcdefg.txt exit eeooff echo done!
远程执行的内容在”<< eeooff“至”eeooff“之间,在远程机器上的操做就位于其中,注意的点:htm
执行本地的脚本blog
咱们在本地建立一个脚本文件test.sh,内容为:rem
ls pwd
echo $0
而后运行下面的命令:get
ssh root@xxx.xxx.xxx.xxx < test.sh
带参数本地脚本
ssh root@xxx.xxx.xxx.xxx 'bash -s' < test.sh helloworld
执行远程服务器上的脚本
ssh root@xxx.xxx.xxx.xxx "/home/nick/test.sh"
执行远程服务器上带参数的脚本
ssh root@xxx.xxx.xxx.xxx /home/nick/test.sh helloworld
参考:
http://www.cnblogs.com/ilfmonday/p/ShellRemote.html(以上内容部分转自此篇文章)
http://www.javashuo.com/article/p-ofwmixvl-dg.html(以上内容部分转自此篇文章)