简体   繁体   English

在bash别名中为ssh替换参数

[英]Make a parameter subsitution in bash aliases for ssh

Is there a way I can create a alias for this command and have it ask for the host. 有没有一种方法可以为此命令创建别名,然后让它询问主机。

ssh -i .ssh/name.pem root@

Thx 谢谢

Something like the following should work (not tested) 类似以下内容应该可以工作(未经测试)

sshfunction(){
  echo "Specify your hostname:"
  read host
  ssh -i .ssh/name.pem root@"$host"
}

Then: 然后:

$ sshfunction

Though if it was me, I'd just provide the hostname as a variable and cut-out the middle man. 虽然是我,但我只是提供主机名作为变量,然后切掉中间人。


Better yet, populate your ~/.ssh/config file (if it doesn't exist you can just create it): 更好的是,填充~/.ssh/config文件(如果不存在,则可以创建它):

host MyHostName
        Hostname 123.456.7.89
        User username

Then: 然后:

$ ssh MyHostName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM