Passwordless SSH Login

原文地址:http://manjeetdahiya.com/2011/03/03/passwordless-ssh-login/

Consider two machines A and B. We want to connect machine B from A over SSH. To do so we have to specify password every time we connect. Here, we can create a setup where SSHing can be done without the password prompt.  On connecting machine B from A, ssh won’t ask for password.

Overview of Setup

  • Generate public and private encryption keys on machine A.
  • Authorize machine A in machine B by appending the public key of A in the file authorized_keysof machine B.

That’s it! You can now access (SSH) machine B from A without specifying the password. B has been now authorized to access A without requiring the password.

Detailed Steps

Method 1

  • Login to machine A and execute the following command:
    ?
    1
    ssh -keygen && ssh -copy- id -i user@B

    The first command generates keys. It will ask for path of the keys and passphrase. Hit Enter key repeatedly to choose the default values.
    The second command adds generated key to B. It will ask for password of user at machine B. And this would be the last time!

Method 2

    • Login to machine A.
    • Generate public and private keys like following:
      ?
      1
      ssh -keygen -t dsa

      It will ask for path of the keys and passphrase. Choose the default path and no password.
      This will generate files id_dsa.pub and id_dsa in ~/.ssh

    • Browse for the above generated keys and copy the public key, that is id_dsa.pub, to the machine B.
    • Login to machine B.
    • Append the public key of A to the file authorized_keys:
      ?
      1
      cat id_dsa.pub >> . ssh /authorized_keys

      Note: Create the directory .ssh in your home if it doesn’t exist.
      You can now delete id_dsa.pub from machine B if you want to.

    • Make sure of the permissions of the directory .ssh and the file authorized_keys are read-write only by the targetted user. Otherwise it might not work.
      ?
      1
      2
      chmod 700 . ssh
      chmod 600 . ssh /authorized_keys
    • Now go back to machine A and SSH machine B. It should not ask for the password.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值