54
52

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

サルでもできるCodeCommit ssh接続でgit cloneするまで

Last updated at Posted at 2015-07-15

サルでもできるCodeCommit コピペでgit cloneするまででhttpsで接続できたので、
ssh接続でも接続したいと思いますよね。

ssh-keygenで公開鍵、秘密鍵を作る

  1. ec2インスタンスにログインしてコンソールから作成
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ec2-user/.ssh/id_rsa): そのままEnter
/home/ec2-user/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): そのままEnter
Enter same passphrase again: そのままEnter
Your identification has been saved in /home/ec2-user/.ssh/id_rsa.
Your public key has been saved in /home/ec2-user/.ssh/id_rsa.pub.
The key fingerprint is:
ce:97:a8:d8:3b:d4:8d:95:22:68:e0:e2:8e:58:8d:ce ec2-user@ip-x-x-x-xx
The key's randomart image is:
+--[ RSA 2048]----+
| . 省略    .     |
+-----------------+

$ cat /home/ec2-user/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAyZfh5ztQIQCwPIQAGFZD9kv1ihU9RP9WCBsfSp7JlNs0eNol
...省略
-----END RSA PRIVATE KEY-----

$ cat /home/ec2-user/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJl+HnO1AhALA8hAAYVkP2S/WKFT1E...省略

公開鍵をCodeCommitのIAMユーザに登録する

  1. IAMユーザを選択する→Upload SSH keyボタン押す
  2. id_rsa.pubの中身をコピペしてUpload SSH keyボタン押す
  3. SSH Key ID が生成される。→.ssh/configに設定する時に必要

ec2インスタンスにログインしてssh接続でgit cloneする

  1. .ssh/congfigに以下を記述。XXXはSSH Key ID
~/.ssh/config
Host git-codecommit.*.amazonaws.com
    User XXXXXXXXXXXXXXX
    IdentityFile ~/.ssh/id_rsa

2. .ssh/configはパーミッション600にする。 $ chmod 600 ~/.ssh/config
3. ssh接続でgit cloneする

$ git clone ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/samlpe_ripo ~/ssh_sample_pipo

最後に

自分の技術ブログではフリーランス界隈の情報や最新のIT情報の発信していますので、よろしくお願いします。

54
52
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
52

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?