Whenever I have to login to a remote server, I have to enter ssh username@hostname and subsequently a password.

I want to save time by omitting some parameters whenever I try to login to a server. I know that one can do this:

sshpass -p 'YourPassword' ssh username@hostname

Is there anyway I can define a function in .bashrc so that I only have to type ssh hostname and it will automatically log me in?


You can do this by setting up your ~/.ssh/ssh_config file and using public-key authentication. For each server you want to log into, set up a Host section in the file with appropriate User and IdentityFile entries.

See man ssh_config for more information.

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.