Set config file of .ssh

As I described in this article, I guess you can't wordmove as default if you use EC2 for remote server. In this article, I introduce how to wordmove with EC2. Actually this is only to use config file of .ssh.

When you create an instance on EC2, you get key pair file and you can log in to it with this file like this.
$ ssh -i /hoge/hoge.pem ec2-user@INSTANCE_NAME
In this situation, you may get error message related to authentication when wordmove command because wordmove can't specify key pair file.
In order to resolve this issue, we can use public key authentication and setting of config of .ssh as below.

1. Generate original key

You generate public and secrete key on your local.
$ ssh-keygen -t rsa
Then you can find key files on ~/.ssh/.

2. Deploy public key on an instance

2-1. Transfer generated key above to the directory of ec2-user

$ scp -i hoge.pem ec2-user@INSTANCE_NAME:/home/ec2-user
If you want to user another user, you need to generate a user in advance and must transfer to a directory of this user.

2-2. Log in to EC2 server and confirm transfer

Log in to EC2 with key pair file.
$ ssh -i /hoge/hoge.pem ~/.ssh/id_rsa.pub ec2-user@INSTANCE_NAME:/ec2-user/

Check transferred file.
$ cd /home/ec2-user
$ ls

2-3. Deploy id_rsa.pub

Make a directory named ".ssh" then transfer id_rsa.pub with name of authorized_keys.
$ mkdir /home/ec2-user/.ssh
$ sudo mv ./id_rsa.pub ./.ssh/authorized_keys

2-4. Change permission of transferred file and made directory

$ sudo chmod 600 /home/ec2-user/.ssh/authorized_keys
$ sudo chmod 700 /home/ec2-user/.ssh

3. Connect via ssh

Run this command and it's successful if you can login.
$ ssh ec2-user@INSTANCE_NAME

4. Add config file on .ssh

With setting till here, you can use wordmove command but it's more useful to add config file when log in with command of ssh. On your local PC, you can write config file like this.

$ vi ~/.ssh/config
Host hoge
    user              ec2-user
    HostName     PUBLIC_DNS_OF_INSTANCE
    Port              22
    IdentityFile    id_rsa

If you can log in to the instance with this command, this setting is successful.
$ ssh hoge
If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Tomohide Kakeya

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment