6

I'm looking for a relatively simple one-line command for bash that will disable the password prompt on future ssh logins (or preferably only the next ssh login), as well as a way to reverse it (the reversal doesn't have to be a one-liner).

Is this possible?

  • Another option would be a tool called sshpass. Once installed you just need to set the SSHPASS variable with your password and then you can use sshpass -e ssh user@host and wont be prompted with a password. You can add something like read -p "What is your ssh password" SSHPASS to your .bash_profile or something if you want to set it at login and not have to worry about it afterwards. – Jesse_b Aug 16 '17 at 15:51
  • 4
    Note that the instructions in all current answers and comments do not disable password authentication. Enabling public key authentication means you don't have to type a password to log in, but it does not disable password authentication, anyone could still use it. An important distinction for security! – marcelm Aug 16 '17 at 16:13
  • @marcelm The first option is what I am looking for. – Theo C Aug 16 '17 at 16:14
  • @marcelm I'm looking to allow access without typing a password at any point. – Theo C Aug 16 '17 at 16:26
11

Simply ssh-copy-id username@host.example.com for one-stop shopping for key-pair authentication.

If you don't already have a keypair to use, generate one: ssh-keygen && ssh-copy-id username@host.example.com.

  • So, I would type something like ssh-keygen && ssh-copy-id user@192.168.0.1 if the connection would come from user@192.168.0.1? – Theo C Aug 16 '17 at 16:06
  • 1
    If the connection would go to user@192.168.0.1. You run the commands on the host you would connect from. – DopeGhoti Aug 16 '17 at 16:31
  • This would be ideal, but then you could even use the ~/.ssh/config and have an entry there with an alias so you could just ssh server1 and it will do a ssh user@server1.example.com and pass off the key for authentication – ivanivan Aug 17 '17 at 16:30
  • True, but that's getting a little bit past the request for a one-liner to set up key-pair SSH authentication (: – DopeGhoti Aug 17 '17 at 16:33
7

You can setup ssh-keys, which let you login to your server without any password. Copy your PC's sshkey from ~/.ssh/idrsa.pub to the server you want to connect to, using ssh-copy-id user@host.

This will let your PC connect to the server without a password using the option ssh -A user@host

If idrsa.pub does not exist, you can create it using the command ssh-keygen

This might not be a one liner, but this can solve your issue. and is quite easy to setup.

1

The answers given here are right, but when you are writing script for this, simple scp doesn't work. Because you need to allow server's public key(fingerprint) for connecting the first time. So when writing the script you need to bypass that by adding -o StrictHostKeyChecking=no option. So now your one-liner will be ssh-copy-id -o StrictHostKeyChecking=no username@host.example.com

and if have not created your ssh-keys yet then ssh-keygen -t rsa -f ~/ -q -P "" & ssh-copy-id -o StrictHostKeyChecking=no username@host.example.com

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.