I would like to copy a text file to a remote host (laptop) via scp. Unfortunately this does not work, because I am always asked for the ssh passphrase.
However, if I start the scp command directly from an open konsole, no ssh passphrase is requested and the text file is copied to the remote host. I would like to define this behavior in a desktop icon so that it works.
Here is a screenshot in which I activate the verbose mode of the scp command so that you can see at which point the execution stops.
SSH_ENV="$HOME/.ssh/agent-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;
}
# 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
A manual scp from the command line works correctly and without asking for the ssh passphrase. But as soon as I wrap the scp command in a desktop icon, as I described above, the ssh passphrase is requested. This worked correctly in Plasma5 but now in Plasma6 (and a Wayland session) it no longer works.
Somehow the call via desktop icon does not seem to be aware of the loaded ssh keys.
Hi, @bedna it worked with the systemd service. Thanks for the hint.I document here again the steps I have done so that other users can easily follow this.
Set up SSH agent based on systemd for a special user
Create the service file under ~/.config/systemd/user/ssh-agent.service.
A lot of people just press the “copy text” from those snippets, and the <code> stuff should not be there.
Thank you again!
You can also press the (choose this answer as solution) on your own answer, that way other users who have the same problem can immediately find the solution linked from you original post.
And since you are such a great person, I will give you a tiny lesson as well.
Instead of doing both enable & start on a systemd service, you can just do: systemctl --user enable --now name-of.service
The --now option starts the service/timer/mount immediately.
Works on both user and system units.