如何编写脚本以使用我的凭据连接到ssh服务器?

1 linux bash perl remote-access remote-server

我想在使用SSH登录远程linux服务器时自动输入密码.

我用了一个可执行的bash脚本

#! /bin/bash

ssh user@machine.remote.host
Run Code Online (Sandbox Code Playgroud)

但有没有办法自动输入密码?

Xu *_*ing 6

ssh-keygen # generate a pair of RSA keys
scp ~/.ssh/id_rsa.pub user@machine.remote.host:id_rsa.tmp # copy the public key to remote host
ssh user@machine.remote.host # ssh to remote server, this time it requires password
cat id_rsa.tmp >> .ssh/authorized_keys # add the public key to authorized_keys
Run Code Online (Sandbox Code Playgroud)

然后你可以注销并登录而无需密码.

  • 文件权限.目标上的目录需要为700,文件需要为600. (2认同)