问题:
如何使用密码自动进行SSH登录?我在配置测试VM,因此不考虑高安全性,
ex )
echo password | ssh id@server
答案1:
不要使用密码。生成无密码的SSH密钥,并推送到您的VM。
如果已经有SSH密钥,就可以跳过此步骤,只需按回车键和两个密码:
$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.
将密钥复制到目标服务器:
$ ssh-copy-id id@server
id@server's password:
现在尝试登录到计算机,使用ssh'id@server'
,然后签入:
.ssh/authorized_keys
以确保我们没有添加你没有期望的额外键。
最后检查登录。
$ ssh id@server
id@server:~$
如果你想用密码保护你的密钥,你也可以使用ssh-agent
,
答案2:
$ sudo apt-get install sshpass
$ sshpass -p your_password ssh user@hostname
答案3
三个简单步骤:
输入以下命令开始生成rsa密钥对:
# ssh-keygen
当出现消息'输入保存密钥的文件'时,按Enter键将文件名保留为空。
当终端要求你输入密码时,只需将此留空,并按Enter键。
然后使用一个简单的命令将密钥对复制到服务器:
# ssh-copy-id userid@hostname
现在你可以不使用密码登录:
# ssh userid@hostname
答案4
使用expect:
#!/usr/bin/expect -f
# ./ssh.exp password 192.168.1.11 id
set pass [lrange $argv 0 0]
set server [lrange $argv 1 1]
set name [lrange $argv 2 2]
spawn ssh $name@$server
match_max 100000
expect"*?assword:*"
send --"$passr"
send --"r"
interact
例如:
# ./1.ex password localhost ooshro
spawn ssh ooshro@localhost
ooshro@localhost's password:
Linux ubuntu-1010-server-01 2.6.35-25-generic-pae #44-Ubuntu SMP Fri Jan 21 19:01:46 UTC 2011 i686 GNU/Linux
Ubuntu 10.10
Welcome to Ubuntu!
* Documentation: https://help.ubuntu.com/
Last login: Tue Mar 1 12:41:12 2011 from localhost
答案5
plink user@domain -pw mypass [cmd]
它也可以在Windows上使用,并且语法与openssh主流的客户端兼容。
相关文章