我正在尝试在服务器之间进行无密码身份验证。之后,我的测试用例将在机器人框架中运行。
我已经尝试过了
*** Settings ***
Library SSHLibrary
Library OperatingSystem
Library String
*** Variables ***
${host1} hostname1
${host1_user} user1
${host1_pass} pass1
${jump} jumbox1
${jump_user} juser
${jump_pass} jpass
${keypresent} false
*** Keywords ***
copy_key_to_jump
${my_pub_key}= OperatingSystem.Get File ~/.ssh/id_rsa.pub encoding=ascii
open connection ${jump}
login ${jump_user} ${jump_pass} 4
execute command echo '${my_pub_key}' >> ~/.ssh/authorized_key
close connection
*** Test Cases ***
connect to host1 and check ipsec
${my_pub_key}= OperatingSystem.Get File ~/.ssh/id_rsa.pub encoding=ascii
open connection ${jump}
login ${jump_user} ${jump_pass} 4
${jump_auth_keys} = execute command cat ~/.ssh/authorized_keys
@{contents}= split to lines ${jump_auth_keys}
:FOR ${line} IN @{contents}
\ ${keypresent}= set variable if "${line.strip()}" == "${my_pub_key.strip()}" true
\ log to console ${\n}${keypresent}
run keyword if "${keypresent}" != "true" copy_key_to_jump
open connection ${host1}
${output}= login ${host1_user} ${host1_pass} look_for_keys=False proxy_cmd=ssh -l ${jump_user} -W ${host1}:22 ${jump}
${ipsec}= execute command ipsec statusall
log to console ${\n}${ipsec}
它有效。但是,还有更好的方法吗? 预先感谢。