打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
SSH login without password

SSH login without password

Your aim

You want to use Linux and OpenSSH to automate your tasks. Thereforeyou need an automatic login from host A / user a to Host B / user b.You don't want to enter any passwords, because you want to call sshfrom a within a shell script.

How to do it

First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/home/a/.ssh/id_rsa): Created directory '/home/a/.ssh'.Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/a/.ssh/id_rsa.Your public key has been saved in /home/a/.ssh/id_rsa.pub.The key fingerprint is:3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .sshb@B's password: 

Finally append a's new public key to b@B:.ssh/authorized_keys andenter b's password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'b@B's password: 

From now on you can log into B as b from A as a without password:

a@A:~> ssh b@B

A note from one of our readers: Depending on your version of SSH you might also have to do thefollowing changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Login without password! (ssh a remote computer)
利用ssh-keygen生成密钥对
如何使得执行scp命令时不需要输入用户密码
ssh-不用密码即可登陆的ssh用户 - 系统管理 - wds
git "Could not read from remote repository.Please make sure you have the correct access rights."解决方案
远程攻略:SecureCRT使用RSA密钥登陆SSH
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服