[resolved] ssh-agent under Mate does not remember the keys.

Graphical Environments, Managers, Multimedia & Desktop questions.
Post Reply
Message
Author
User avatar
Zaxon_
Posts: 25
Joined: 2014-08-21 13:09
Has thanked: 1 time
Been thanked: 1 time

[resolved] ssh-agent under Mate does not remember the keys.

#1 Post by Zaxon_ »

When I was using xfce4 I had the following code in my .bashrc file in order to type the ssh key password only once, and then each other terminal I will be opening will not require the ssh key password as it will be provided by the ssh-agent.

Code: Select all

## ssh agent config
SSH_ENV="$HOME/.ssh/environment"

function start_agent {
     echo "Initialising new SSH agent..."
     /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
     echo succeeded
     chmod 600 "${SSH_ENV}"
     . "${SSH_ENV}" > /dev/null
     /usr/bin/ssh-add ~/.ssh/id_rsa
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
     . "${SSH_ENV}" > /dev/null
     #ps ${SSH_AGENT_PID} doesn't work under cywgin
     ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { start_agent; }
else
     start_agent;
fi
XFCE4: After first open terminal I was asked about the password, but then new terminals did not ask anything when I tried to SSH to the remote location.

MATE: Every time I SSH to remote location the password is asked.

So how to make this work under MATE?

Regards,
Zaxon
Last edited by Zaxon_ on 2019-08-09 06:40, edited 1 time in total.

User avatar
Zaxon_
Posts: 25
Joined: 2014-08-21 13:09
Has thanked: 1 time
Been thanked: 1 time

Re: ssh-agent under Mate does not remember the keys.

#2 Post by Zaxon_ »

OK. I will answer myself then (as I found a solution). :)

I replaced the code in my .bashrc with the following:

Code: Select all

## ssh agent config
. source-ssh-agent
And the content of the source-ssh-agent is:

Code: Select all

#!/bin/bash
# source-ssh-agent: Script to source for ssh-agent to work.

# Check if accidentaly executed instead of sourced:
if echo "$0" | grep -q source-ssh-agent; then
	echo "source-ssh-agent: Do not execute directly - source me instead!"
	exit 1
fi

export SSH_AUTH_SOCK=/tmp/ssh-agent

start_agent() {
	rm -f $SSH_AUTH_SOCK
	ssh-agent -a $SSH_AUTH_SOCK > /dev/null
	ssh-add
}

MESSAGE=$(ssh-add -L 2>&1)
if [ "$MESSAGE" = 'Could not open a connection to your authentication agent.' -o \
     "$MESSAGE" = 'Error connecting to agent: Connection refused' -o \
     "$MESSAGE" = 'Error connecting to agent: No such file or directory' ]; then
	start_agent
elif [ "$MESSAGE" = "The agent has no identities." ]; then
	ssh-add
fi

Post Reply