2

I'm looking for a Linux utility that lets me avoid having to re-type my SSH passwords every time I login, i.e. something just like ssh-agent, but for regular old passwords instead of SSH private key passphrases.

Just using SSH keys is not an option because for some reason they have been disabled on the server in question. I'd also prefer not to store passwords permanently on my hard disk (e.g. in ~/.ssh/config), which is why I'm asking specifically for something like ssh-agent that works on a per-desktop-session basis.

1

Default Linux ssh client can keep connections open for reuse.

Preconditions:

You need to set up your ~/.ssh/config to include a ControlMaster and ControlPath:

Host server
    Hostname example.com
    User username
    ServerAliveInterval 120
    ControlMaster auto
    ControlPath ~/.ssh/control:%h:%p:%r

Then just type:

ssh -fN server

# -f      Requests ssh to go to background just before command execution.
# -N      Do not execute a remote command.

You must type in your password.
This opens a connection and puts it in the background.

Then run ssh server, it will reuse that connection without the need for giving the password.

You can close and open connections without the need for a password until the background connection gets killed or when you restart your computer. This method also works across (multiple) hop servers.

To close an open connection, run:

ssh -O exit server

or just kill the process:

pkill -f 'ssh -fN server'

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.