在 mac 上通过 ssh 连接到亚马逊 aws linux 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14229846/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
connecting to amazon aws linux server by ssh on mac
提问by brno792
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.
我创建了一个新的密钥对并将其下载到我的 mac,然后使用该密钥对和我的安全组设置了一个新的 Amazon Linux AMI 服务器。现在我需要将我下载的密钥对 .pem 文件放在我的用户文件夹中的 .ssh 文件中吗?但是由于名称的原因,我无法创建一个名为“.ssh”的文件夹。
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.
我应该将密钥对放在我的 Mac 上的什么位置?然后需要什么 chmods 或其他命令才能从我的 linux bash 连接到服务器?我知道“ssh 我的公共 DNS”,但我应该注意哪些其他权限或其他事项?这是一个新手问题。谢谢。
采纳答案by jarriett
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
您需要将密钥对放在 {your home directory}/.ssh 中。如果该文件夹不存在,请创建它。将密钥对放入其中后,您必须更改文件的权限,以便只有您的用户可以读取它。启动终端并输入
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.
您必须限制访问,因为 OpenSSH 协议不允许您使用其他人可以查看的密钥。
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>
ssh -i <your home directory>/.ssh/<your keypair file> ec2-user@<ec2 hostname>
回答by Kevin Willock
you can also create a file ~/.ssh/config chmod it 644 then inside you can add something like this
你也可以创建一个文件 ~/.ssh/config chmod it 644 然后在里面你可以添加这样的东西
host mybox-root
Hostname [the IP or dns name]
User root
IdentityFile ~/.ssh/[your keypair here]
then you can just do
那么你可以做
$ ssh mybox-root
$ ssh mybox-root
and you'll login easier.
你会更容易登录。
回答by sent.ror
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.
您可以在 Macbook pro 中使用 Java MindTerm 连接到您的 EC2 服务器。这个对我有用。这是更多详细信息和分步说明。
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html
回答by lopezi
回答by Atit Charan
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 ...
有人在 Mac 上询问创建 ~/.ssh 文件夹的简单方法是运行命令 ssh-keygen,然后使用以下设置...
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:
B.然后创建:
touch ~/.ssh/authorized_keys
C. Fix the permissions:
C. 修复权限:
chmod 600 ~/.ssh/authorized_keys
D. Copy AWS Key to that file:
D. 将 AWS 密钥复制到该文件:
cp AWS_key.text ~sam/.ssh/authorized_keys
#You would have saved this SSH key earlier when creating the EC2 instance
#您应该在创建 EC2 实例时提前保存此 SSH 密钥
E. Then test the ssh to AWS Linux server - you will see this error:
E. 然后测试 ssh 到 AWS Linux 服务器 - 你会看到这个错误:
ssh -i ./authorized_keys [email protected]
Please login as the user "ec2-user" rather than the user "root".
请以用户“ec2-user”而非用户“root”的身份登录。
F. Re-try that and it should work with allowed AWS user "ec2-user":
F. 重试,它应该可以与允许的 AWS 用户“ec2-user”一起使用:
ssh -i ./authorized_keys [email protected]
__| __|_ )
_| ( / 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.
希望这有帮助,?一切顺利。