Devon
Devon

Reputation: 335

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

Upvotes: 1

Views: 406

Answers (1)

Joe Healey
Joe Healey

Reputation: 1252

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):

host MyHostName
        Hostname 123.456.7.89
        User username

Then:

$ ssh MyHostName

Upvotes: 4

Related Questions