使用sshpass进行ssh/scp/sftp/自动输入密码

1,ssh

ssh 端口为默认22的时候:

#sshpass -p userpassword ssh  -o StrictHostKeyChecking=no  username@serverip "ls /"

ssh 端口不是默认22的时候,假如为1234

#sshpass -p userpassword ssh  -o StrictHostKeyChecking=no -p1234 username@serverip "ls /"



2,scp
sshpass -p "$2" scp -r -o StrictHostKeyChecking=no $srcfile username@hostname:$descPath


3,sftp
sshpass -p "$2" sftp -o StrictHostKeyChecking=no username@hostname:$romotefilename $localpath

你可能感兴趣的:(Java基础)