i know how can ssh to server as

$ ssh <user>@<domain>

then second the command prompt ask for password as

<user>@<domain>'s password : -----

here how can be able to do same with one line ?, that looks like

$ssh <user>@<domain-name> -p <pass>

is it possible ? if yes how ?

2 Answers 2


There are several ways to help you doing this. But you may have a security concern in mind while using those tools.

  1. ssh-key without passphrase (lack of security here)

You can create a ssh-key and add it to the trusted keys on your distant server.

  1. ssh-key with ssh-agent

You can create a ssh-key with a passphrase (more secure) and use ssh-agent to help with automation.

  1. ssh config file

This file may help to pair keys with servers


The other answer is correct, and describes the proper solution from security point of view. But also to answer the question, there is sshpass, which does exactly what you want.

You can get the password from command-line, from file, file descriptor or from environment variable. For example

sshpass -p password ssh user@domain

But note that this simple use case is security disaster, since all your commands are logged in the history on your disk, which is something you usually don't want to happen with passwords.

  • 1
    And while a command is executing, the command line is visible to other users on the system.
    – kasperd
    Feb 17, 2016 at 17:49

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