1

I have multiple ssh connections I want to add to the config file in the .ssh directory, but it seems the password field is not catered for. Below is the error I get:

console error after running ssh

Is there any workaround for this?

Conrad96
  • 11
  • 2

1 Answers1

2

There is no way for providing password in ssh config.

You should use ssh keys instead.

But, if you would like to work around it, keep in mind that saving passwords in plain text is insecure.

Simple workaround would be creating a ssh wrapper with sshpass on top.

Install sshpass first:

sudo apt install sshpass

Prepare a bash script for a wrapper:

touch $HOME/.ssh/sshp.sh
chmod 700 $HOME/.ssh/sshp.sh

Paste this code into $HOME/.ssh/sshp.sh

#!/bin/bash

SSH_HOST=$1

if [[ ! "$SSH_HOST" ]]; then echo "provide ssh_host as first argument" ; exit 1 ; fi

sshpass -p "$(cat $HOME/.ssh/passwords/$SSH_HOST)" ssh $SSH_HOST

Edit ~/.bashrc and add:

alias sshp='$HOME/.ssh/sshp.sh'

Then type:

source ~/.bashrc

Next, save passwords for your hosts like this:

mkdir $HOME/.ssh/passwords
chmod 700 $HOME/.ssh/passwords
echo -n "password" > $HOME/.ssh/passwords/EXAMPLEHOST1
echo -n "password" > $HOME/.ssh/passwords/EXAMPLEHOST2
echo -n "password" > $HOME/.ssh/passwords/EXAMPLEHOST3

Clean current bash history once you've saved your passwords.

history -c

And use sshp alias instead ssh to connect to your server:

sshp EXAMPLEHOST1
Comar
  • 1,485