Alias to connect to AWS instance via SSH not working

0

I made an alias to make it easier to connect to my AWS EC2 instance. Although there is an error. Here is the code in ~/.bash_profile:

alias aws_connect=‘ssh -i /path/to/keyfile.pem  ec2-user@xx.xxx.xxx.xxx’

When I type "aws_connect in the terminal, this is what comes out: -bash: “ssh: command not found. This is the output when I type source ~/.bash_profile:

MacBook-Pro:~ username$ source ~/.bash_profile
-bash: alias: -i: not found
-bash: alias: /path/to/keyfile.pem: not found
-bash: alias: ec2-user@xx.xxx.xxx.xxx”: not found

Can anyone see what I did wrong?

Isserlis

Posted 2014-08-19T05:45:15.787

Reputation: 75

1Is that a cut and paste? If so, the quote marks are wrong - they should be ' not ‘’ – Paul – 2014-08-19T05:59:22.180

That worked. OS X automatically makes ' into ‘’. – Isserlis – 2014-08-19T18:20:01.980

Answers

1

Why not using ssh config for this?

You can achieve this by creating a config file in your ~/.ssh folder:

vim ~/.ssh/config and then add something like this:

Host example HostName Server_IP_or_hostname User SSH_USER IdentityFile ~/path/to_your_key

And then when you want to ssh all you have to do is type:

ssh example

<2cents>

mariusv

Posted 2014-08-19T05:45:15.787

Reputation: 11

Ah, I didn't know this was possible. I'm new to OS X. Thanks. – Isserlis – 2014-08-23T00:52:23.840

No problem. This works in both OSX and Linux and is really helpful when you have quite few servers to connect on :-) – mariusv – 2014-08-23T07:59:22.747