导航:首页 > 程序命令 > sshpass命令

sshpass命令

发布时间:2025-01-18 12:33:54

① 如何自动输入密码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到对应机器上了

linux下怎样设置ssh无密码登录

有两种方法,可以用证书实现无密码登录,或者sshpass命令可以指定ssh登陆密码。
1、派出间谍
Step 1:执行ssh-keygen -t rsa,会在~/.ssh下生成两个文件,id_isa和id_isa.pub
On one of the local LINUX (not SGI) machines, generate an id_rsa and id_rsa.pub pair as follows (this machine will subsequently be referred to as your home machine):
ssh-keygen will create the files ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub.
Step 2: Copy the contents of ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys on any and all machines to which you want to be able to ssh to without being prompted for a password
可以用下面的命令完成此步骤:
cat id_rsa.pub |ssh [email protected] ‘cat ->> ~/.ssh/authorized_keys’
2、用sshpass程序
安装:
tar zxf sshpass-1.05.tar.gz
cd sshpass-1.05
./configure;make;make install
which sshpass
/usr/local/bin/sshpass
实例:
sshpass -p “passwd” ssh root@ip

阅读全文

与sshpass命令相关的资料

热点内容
如何朗读pdf 浏览:744
压缩机启动后继电器发烫 浏览:405
小学编程项目学习 浏览:555
net编译运行原理 浏览:783
加密电脑的文件拷出来打不开 浏览:364
可达性算法根 浏览:206
ibm的服务器怎么安装系统 浏览:490
pdftomobi在线 浏览:795
phprsa密码算法 浏览:36
51单片机定时器暂停并加减 浏览:489
解压粘粘球怎么弄 浏览:177
人气热点个股的选股指标源码 浏览:980
三星buds安卓手机怎么连接 浏览:679
苹果手机微信资料如何转移到安卓手机 浏览:942
什么是面向对象编程语言 浏览:432
javaweb嵌入式 浏览:893
linux怎么设置多个文件夹 浏览:679
bat命令删除文件 浏览:608
三星s8加密视频 浏览:254
python内置库的使用 浏览:785