㈠ 求一个shell脚本,能远程登录到另外一台机器上,并且在这台机器上执行一个shell(脚本中需要传进去一个参数)
首先要设置ssh信任 ----> 实现无密码ssh登录. 这个你可以自行搜索,
脚本非常简单:
sshuser@host"command$var"
㈡ linux下如何使用ssh远程登录主机 执行shell脚本
知道linux的ip,用户和密码就可以远程登陆了。在你的SSH 客户端会有一个linux的终端。在这执行命令就可以了。
㈢ 如何自动输入密码ssh连接到其他机器
主要的解决方法有三种:
1. 生成ssh公钥,建立和对方机器的信任关系;
2. 使用expect脚本;
3. 使用sshpass。
这里介绍一下sshpass相关内容
下载并安装sshpass):
# tar zxvf sshpass-xxxx.tar.gz
# cd sshpass-xxxx
# ./configure
# make && make install
基本用法:sshpass -p [密码] ssh [user]@[host]
免去第一次登录机器时的确认提示(Are you sure you want to continue connecting (yes/no)):
sshpass -p [密码] ssh [user]@[host] -o StrictHostKeyChecking=no
后面也可以跟上其他ssh命令,如scp等
例1,公司的一个环境,大部分机器的login密码是"1root",少部分是"123qwe",新建一个hssh.sh文件,按如下修改,到/usr/bin/目录下。
[cpp] view plain
#!/bin/sh
#_main_
temp_file=/tmp/hssh.1
ip=192.168.$1
case "$1" in
"204.188"|"207.31"|"205.199") password="123qwe";;
*) password="1root"
esac
sshpass -p $password ssh root@$ip -o StrictHostKeyChecking=no 2>$temp_file
if [ $? != 0 ];then
#for some reason,machine had reinstall, we need to delete that IP address in known_hosts file before ssh it.
grep -q "REMOTE HOST IDENTIFICATION HAS CHANGED" $temp_file
if [ $? = 0 ];then
key_file=`grep "Offending key in" $temp_file | cut -d' ' -f 4 | cut -d ':' -f1 2>/dev/null`
cat $key_file | grep -v "$ip" > $temp_file
sudo cp -v $temp_file $key_file
sshpass -p $password ssh root@$ip -o StrictHostKeyChecking=no 2>$temp_file
fi
fi
那么我们每次只要输入hssh XXX.XXX 等就可以ssh到对应机器上了
㈣ shell脚本中怎么ssh上远程机执行命令
你好,
先在两台机子上建立信任,ssh-key
具体方法网络下就有
脚本里的命令是
ssh 用户@ip
㈤ shell脚本如何写入带有ssh密码登陆主机
SSH是不能实现的,试试expect
#!/usr/bin/expect
spawn /usr/bin/ssh [email protected]
expect
"*password:"
send "123456\r"
expect "*]#"
send "cd /root"
expect
"*]#"
send "exit\r"
expect eof
㈥ linux下如何使用shell脚本进行ssh远程登陆到其他机器执行停止进程的命令。 用户名/密码:test/12345h
ssh [email protected] 输入密码,登陆成功后
ps -ef 查看进程pid
或者 netstat -ntpl
kill -9 进程pid
㈦ 在LINUX系统下,如何使用SHell脚本,SSH登陆上路由器
登陆linux系统,打开终端命令。输入 rpm -qa |grep ssh 查找当前系统是否已经安装
2.如果没有安装SSH软件包,可以通过yum 或rpm安装包进行安装
3、安装好了之后,就开启ssh服务。Ssh服务一般叫做 SSHD
4、命令行输入 service sshd start 可以启动 或者使用 /etc/init.d/sshd start
5、输入:ssh 账号@IP地址即可。
比如:ssh [email protected]
然后按照提示输入密码. 一切无误则进入该远程主机.