![通过 SSH 连接到 AWS 实例的别名不起作用](https://linux22.com/image/1419872/%E9%80%9A%E8%BF%87%20SSH%20%E8%BF%9E%E6%8E%A5%E5%88%B0%20AWS%20%E5%AE%9E%E4%BE%8B%E7%9A%84%E5%88%AB%E5%90%8D%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我创建了一个别名,以便更轻松地连接到我的 AWS EC2 实例。虽然有一个错误。以下是代码~/.bash_profile
:
alias aws_connect=‘ssh -i /path/to/keyfile.pem [email protected]’
当我在终端中输入“aws_connect”时,输出的内容如下:-bash: “ssh: command not found
。这是我输入时的输出source ~/.bash_profile
:
MacBook-Pro:~ username$ source ~/.bash_profile
-bash: alias: -i: not found
-bash: alias: /path/to/keyfile.pem: not found
-bash: alias: [email protected]”: not found
有人能看出我做错了什么吗?
答案1
为什么不使用 ssh 配置呢?
您可以通过在文件夹中创建配置文件来实现此目的~/.ssh
:
vim ~/.ssh/config
然后添加如下内容:
Host example HostName Server_IP_or_hostname User SSH_USER IdentityFile ~/path/to_your_key
然后,当您想要 ssh 时,您只需输入:
ssh example
<2分>