connecting to amazon aws linux server by ssh on ma

2019-03-08 01:56发布

I created a new keypair and downloaded it to my mac, then set up a new Amazon Linux AMI server with that keypair and my security group. Now I need to put the keypair .pem file that I downloaded in a .ssh file in my users folder? I am unable to create a folder called ".ssh" however because of the name.

Where do I put the keypair on my mac? and what chmods or other commands are then needed to connect to the server from my linux bash? I know "ssh my public DNS" but what other permissions or anything else should I be aware of? Its a newbie question. Thanks.

5条回答
家丑人穷心不美
2楼-- · 2019-03-08 02:28

you can also create a file ~/.ssh/config chmod it 644 then inside you can add something like this

host mybox-root
  Hostname [the IP or dns name]
  User root
  IdentityFile ~/.ssh/[your keypair here]

then you can just do

$ ssh mybox-root

and you'll login easier.

查看更多
Explosion°爆炸
3楼-- · 2019-03-08 02:30

Someone was asking on Mac's an easy way to create the ~/.ssh folder would be by running command ssh-keygen, then use following setup ...

A.

macbook-air$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/sam/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/sam/.ssh/id_rsa.
Your public key has been saved in /Users/sam/.ssh/id_rsa.pub.

B. Then create:

touch ~/.ssh/authorized_keys

C. Fix the permissions:

chmod 600 ~/.ssh/authorized_keys

D. Copy AWS Key to that file:

cp AWS_key.text ~sam/.ssh/authorized_keys

#You would have saved this SSH key earlier when creating the EC2 instance

E. Then test the ssh to AWS Linux server - you will see this error:

ssh -i ./authorized_keys root@ec2-54-76-176-29.ap-southeast-2.compute.amazonaws.com

Please login as the user "ec2-user" rather than the user "root".

F. Re-try that and it should work with allowed AWS user "ec2-user":

ssh -i ./authorized_keys ec2-user@ec2-54-76-176-29.ap-southeast-2.compute.amazonaws.com
       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2014.09-release-notes/
9 package(s) needed for security, out of 12 available
Run "sudo yum update" to apply all updates.

Hope this helps, all the best.

查看更多
淡お忘
4楼-- · 2019-03-08 02:36

You'll want to put the keypair in {your home directory}/.ssh . If that folder doesn't exist, create it. Once you put the keypair in there you have to change the permissions on the file so only your user can read it. Launch the terminal and type

chmod 600 $HOME/.ssh/<your keypair file>

That limits access to the file, and then to limit access to the folder type

chmod 700 $HOME/.ssh

You have to limit the access because the OpenSSH protocol won't let you use a key that other's can view.

Then to log into your instance, from the terminal you would enter

ssh -i <your home directory>/.ssh/<your keypair file> ec2-user@<ec2 hostname>

查看更多
我命由我不由天
6楼-- · 2019-03-08 02:40

You can use Java MindTerm to connect to your EC2 server in Macbook pro. It works for me. here are the more details and step by step instruction.

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

查看更多
登录 后发表回答