官术网_书友最值得收藏!

Managing SSH keys

Heroku manages access to our application's Git repository with SSH keys. When we first set up the Heroku Toolbelt, we had to upload either a new or existing public key to Heroku's servers. This key allows us to access our Heroku Git repositories without entering our password each time.

If we ever want to deploy our Heroku applications from another computer, we'll either need to have the same key on that computer or provide Heroku with an additional one. It's easy enough to do this via the CLI, which we'll learn in this recipe.

How to do it…

To get started, let's fire up a terminal. We'll be using the keys command in this recipe by performing the following steps:

  1. First, let's view all of the existing keys in our Heroku account:
    $ heroku keys
    === coutermarsh.mike@gmail.com Keys
    ssh-rsa AAAAB3NzaC...46hEzt1Q== coutermarsh.mike@gmail.com
    ssh-rsa AAAAB3NzaC...6EU7Qr3S/v coutermarsh.mike@gmail.com
    ssh-rsa AAAAB3NzaC...bqCJkM4w== coutermarsh.mike@gmail.com
    
  2. To remove an existing key, we can use keys:remove. To the command, we need to pass a string that matches one of the keys:
    $ heroku keys:remove "7Qr3S/v coutermarsh.mike@gmail.com"
    Removing 7Qr3S/v coutermarsh.mike@gmail.com SSH key... done
    
  3. To add our current user's public key, we can use keys:add. This will look on our machine for a public key (~/.ssh/id_rsa.pub) and upload it:
    $ heroku keys:add
    Found existing public key: /Users/mike/.ssh/id_rsa.pub
    Uploading SSH public key /Users/mike/.ssh/id_rsa.pub… done
    

    Note

    To create a new SSH key, we can run $ ssh-keygen -t rsa.

  4. If we'd like, we can also specify where the key is located if it is not in the default /.ssh/ directory:
    $ heroku keys:add /path/to/key.pub
    

How it works…

SSH keys are the standard method for password-less authentication. There are two parts to each SSH key. There is a private key, which stays on our machine and should never be shared, and there is a public key, which we can freely upload and share.

Each key has its purpose. The public key is used to encrypt messages. The private key is used to decrypt messages.

When we try to connect to our Git repositories, Heroku's server uses our public key to create an encrypted message that can only be decrypted by our private key. The server then sends the message to our machine; our machine's SSH client decrypts it and sends the response to the server. Sending the correct response successfully authenticates us.

Note

SSH keys are not used for authentication to the Heroku CLI. The CLI uses an authentication token that is stored in our ~/.netrc file.

主站蜘蛛池模板: 吴桥县| 惠安县| 镇雄县| 合江县| 鸡西市| 昌吉市| 桐庐县| 大英县| 屏东市| 上虞市| 石嘴山市| 饶阳县| 车险| 张掖市| 高淳县| 佛山市| 江西省| 南平市| 友谊县| 辉南县| 历史| 哈巴河县| 阜新| 德令哈市| 古丈县| 栖霞市| 江都市| 读书| 新源县| 来宾市| 瑞昌市| 稻城县| 长葛市| 抚远县| 个旧市| 富锦市| 东莞市| 东乡县| 公安县| 牟定县| 阳原县|