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
    Commented Aug 16, 2017 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
    Commented Aug 16, 2017 at 16:13
  • @marcelm The first option is what I am looking for.
    – user211677
    Commented Aug 16, 2017 at 16:14
  • @marcelm I'm looking to allow access without typing a password at any point.
    – user211677
    Commented Aug 16, 2017 at 16:26

3 Answers 3


Simply ssh-copy-id [email protected] 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 [email protected].

  • So, I would type something like ssh-keygen && ssh-copy-id [email protected] if the connection would come from [email protected]?
    – user211677
    Commented Aug 16, 2017 at 16:06
  • 1
    If the connection would go to [email protected]. You run the commands on the host you would connect from.
    – DopeGhoti
    Commented Aug 16, 2017 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 [email protected] and pass off the key for authentication
    – ivanivan
    Commented Aug 17, 2017 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
    Commented Aug 17, 2017 at 16:33

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.


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 [email protected]

and if have not created your ssh-keys yet then ssh-keygen -t rsa -f ~/ -q -P "" & ssh-copy-id -o StrictHostKeyChecking=no [email protected]

You must log in to answer this question.