0

Would it be possible to store the login by default for ssh server in a configuration file?

I have plenty of server with different credentials. I am using the same ssh key for all of them, but I always forgot the login I need. Instead of writing:

$ ssh [email protected]

I would like to use:

$ ssh myserver.inc 

And it would use the login configured for that server. In the case I need to login with a different credentials, I still can manually at the login@ prefix.

Is that possible?

1 Answer 1

3

You can set this up by using ~/.ssh/config. Create the file with the lines

Host myserver.inc
User tbuser22

You can have multiple host sections in the file. Other parameters can also be set on a per-host basis, like IdentityFile, and paramteres are in effect until the next Host line.

You can also have universal settings by having Host * as your last entry in the file and parameters set here apply to all hosts unless specifically overridden. When you have multiple Host lines, they are read in order and the first match is used. Wildcards can be used in defining the matched host. Thanks @user1686 for catching this.

Any command-line parameters will take priority over settings in the config file.

1
  • 1
    ssh_config uses the opposite order – individual host sections should go first, and the catch-all Host * should go last, as only the first instance of a parameter is used. Sep 23, 2022 at 12:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .