I connect to many servers daily. my ssh config default username is "admin"

but servers comes from different environnements and username can changes. sometimes it will be "ec2-user" or "exploitation" or "something-else" ...

Is there a way SSH remember that last connection to was with "ec2-user" ?

So I don't have to specify "-l ec2-user" next time.


You can set these up yourself in your configuration file $HOME/.ssh/config.

For example:

Host *.amazonaws.com
        User ec2-user

        User centos
  • sadly, there is no rule/pattern that can group servers. I can have ec2-user or admin or centos inside amazon servers – exeral Nov 18 '20 at 22:15
  • @exeral You're going to have a lengthy config file then. – Michael Hampton Nov 19 '20 at 9:10
  • You can put defaults at the end of the file, and override them earlier in the file. So if you want to use the user ec2-user on most *.amazonaws.com servers, but admin or centos on only a few, you can put an entry for Host *.amazonaws.com, User ec2-user at the end of the file and entries for the others earlier. Or override it on the command line for those anomalous hosts. – Gordon Davisson Nov 19 '20 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.