Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using ubuntu 11.10. I'm using ssh for connecting to many servers daily, so i put their parameters in .ssh/config file; like this :

Host Home
User netmoon
Port 22

Is there a way to put passwords in this file, for each connection? So when server asks for password, terminal put its pass and send it to server.

It's because sometimes I stand away from the pc and when I go back and type password, and press enter, terminal said CONNECTION CLOSED.

  • I don't want to use public/private key pair.
share|improve this question
I'm in the same situation and I cannot upload my public key because I have ssh access only for svn. That is if I try ssh svnhost I get "( success ( 2 2 ( ) ( edit-pipeline svndiff1 absent-entries commit-revprops depth log-revprops partial-replay ) ) )" svnserve response and not the shell – Uberto Oct 25 '12 at 14:27
See and… for a way by utilizing SSH_ASKPASS. – Olaf Dietsche Jun 27 '15 at 9:41
up vote 13 down vote accepted

If you don't really want to use a public/private key pair, you can write a expect script to enter the password for you automatically depending on the destination address.

Edit: What I mean is that you can have a script that, on one hand, uses expect to enter the password for you and, on the other hand, reads the password for a given user and host from a configuration file. For example, the following python script will work for the sunny day scenario:

import argparse
from ConfigParser import ConfigParser
import pexpect

def main(args):
    url = args.url
    user, host = url.split('@', 1)

    cfg_file = 'ssh.cfg'
    cfg = ConfigParser()
    passwd = cfg.get(user, host)

    child = pexpect.spawn('ssh {0}'.format(url))

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Run ssh through pexpect')
    args = parser.parse_args()

and the configuration file format would be as follows:

host1 = passwd_1
host2 = passwd_2

host1 = passwd_1
host2 = passwd_2

Note: As explained, the python script would need to be much more complex to handle all the possible errors and question messages from ssh and all the possible urls (in the example it's assumed that it will be something like user@host, but the user part isn't used most of the times), but the basic idea would still be the same. Regading the configuration file, you may use a different configuration file or use .ssh/config and write your own code to parse that file and get the password for a given user and host.

share|improve this answer
can you explain further? – Netmoon Dec 16 '11 at 6:29
@Netmoon I added a small example to my answer to my it clearer. – jcollado Dec 18 '11 at 13:14
This doesn't answer the question of how to put the password in the .ssh/config file – Eric Woodruff Mar 18 at 18:20

Trading off security for convenience never ends well...

Could you use ssh-copy-id from the openssh-client package?

From man ssh-copy-id:

ssh-copy-id is a script that uses ssh to log into a remote 
machine and append the indicated identity file to that 
machine's ~/.ssh/authorized_keys file.
share|improve this answer
This doesn't work if the remote admin insists on disabling public key authorization... – tomasz Sep 25 '14 at 21:36
Yes, but being realistic on systems under your entire direct supervision and control is not making a compromise. Say, for example, on a vagrant virtual machine with no outside connections used solely for development purposes on a single seat. – Scott Oct 30 '14 at 18:29
Insisting on draconian security without cause also never ends well. – cwallenpoole Dec 23 '14 at 17:22
Sometimes it ends well. – devth Sep 22 '15 at 0:26
IMHO, the insistence of passwords for authentication is more risk than not. I oftentimes set often used passwords for ssh as environment variables as I am loath to remember a set of arbitrary strings. By demanding users enter them is simply asking them to be poorly stored. – eggmatters Feb 16 at 17:32

No. This is not possible I'm afraid.

The only real alternative is to use private keys but you've said you don't want to (why not?).

share|improve this answer
because i don't have permission to put another key on server. – Netmoon Dec 15 '11 at 11:42
@Netmoon: If you can log in, you can add a key, right? You only need write access to your home directory, unless the sysadmin set things up strangely. – Scott Severance Dec 20 '11 at 4:07
@ScottSeverance I think that is the situation this question refers to. Not having the ability to add a key. Yes it is strange, but it often happens. – user239558 May 16 '13 at 15:16
I've had the very common experience of shared hosting environments where public key access is disabled, so even though you can add keys, they are not used. it goes against reason yes, but that's the way many hosting providers set up their servers – billynoah Jun 9 '14 at 14:01
Thank you!! for the straight answer. – laggingreflex Nov 20 '14 at 13:27

There also is sshpass program for that. How to use: sshpass -p MyPa55word ssh

share|improve this answer
Unless you preface your command with a space, (sshpass instead of sshpass), you have just stored your password ("MyPa55word") in your shell's history file. – waltinator Jun 29 at 18:27

I use an application from VanDyke Software called SecureCRT.

It is not free, but very reasonably priced. I have used it for years (running on Windows, or using Wine) for remote access, terminal emulation, and (dispersed) network management. They finally released a native Linux version of this at the beginning of 2011.

It has support for complex login settings (or scripts), stored passwords (or certificates), tabbed multiple sessions, etc.

At startup you can choose which remote target (and protocol) from a structured list (tree view) of stored remote (or local) machines, or just create a connection (which is then stored).

I have found it particularly useful for remote sites with advanced authentication, non-standard ports, or firewall-access negotiation.

If you are doing remote access a lot (part of your main role), then this application will justify its expense in the first month of use.

share|improve this answer
sorry, i don't understand. can you explain ? – Netmoon Dec 16 '11 at 6:38
reworded for you .. – david6 Dec 16 '11 at 9:13
thanks, completely got it. – Netmoon Dec 16 '11 at 15:04
Since posting of the above response there has been several iterations of SecureCRT, including the latest one VanDyke just released in early December 2013. Each iteration has been improving the program making it even more versatile. It also has a rich API that allows the program to be controlled/interfaced with Python/VB scripts. SecureCRT has been part of my core toolkit for a good decade, and I highly recommend it. – Ville Dec 19 '13 at 21:15
Agreed. I continue to beta-test each new release, and was heavily involved in early testing for porting to Ubuntu. – david6 Dec 19 '13 at 22:36

How about ProxyCommand:

Host Home-raw
Host Home
   User netmoon
   Port 22
   ProxyCommand sshpass -pmypass ssh netmoon@%h-raw nc localhost %p
share|improve this answer

The answer of @BrunoPereira to this question shows an alternative method to connect without explicitly entering a password and avoiding ssh keys.

You could create a script, an alias or a function in your ~/.bashrc to quickly execute that command.

Obviously, there are security consideration you should take into account with this approach.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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