You are not logged in.

#1 2019-11-05 14:39:02

LinuxShadow
Member
Registered: 2019-05-04
Posts: 26

Setting up ssh-agent via bashrc

Hi there,

I'm currently working on getting ssh-agent running via bashrc and ran into a problem:

Whenever I open a terminal I get the following error:

bash: /run/user/1000/ssh-agent.env: No such file or directory

My ~/.bashrc:

#
# ~/.bashrc
#

# start ssh-agent
if ! pgrep -u "$USER" ssh-agent > /dev/null; then
  ssh-agent > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
if [[ ! "$SSH_AUTH_SOCK" ]]; then
  eval "$(<"$XDG_RUNTIME_DIR/ssh-agent.env")"
fi
# end start ssh agent

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '

Running

ls $XDG_RUNTIME_DIR

I can see that there is no file or directory called ssh-agent.env.
The question is: How can I solve this? Should I just create such a directory or file and what should I put into there?

LinuxShadow

Offline

#2 2019-11-05 15:35:54

Stefan_xyz
Member
Registered: 2019-09-01
Posts: 107

Re: Setting up ssh-agent via bashrc

Not sure if there's a difference, but why don't you install an SSH Server?

Offline

#3 2019-11-06 15:23:13

eda2z
Member
From: Woodstock, IL
Registered: 2015-04-21
Posts: 71

Re: Setting up ssh-agent via bashrc

I was also looking into ssh-agent so I tried executing similar lines from the command prompt. The call to ssh-agent (7th line) created the .env file and also started ssh-agent executing. If I rm the .env file and try again then the file is not created since ssh-agent is currently running. Perhaps you have a copy of ssh-agent running?

Offline

#4 2019-11-19 15:06:37

LinuxShadow
Member
Registered: 2019-05-04
Posts: 26

Re: Setting up ssh-agent via bashrc

Stefan_xyz wrote:

Not sure if there's a difference, but why don't you install an SSH Server?

Sorry for the long time it took me to respond, but by looking at your Arch Wiki entry, I don't think I'll require OpenSSH. I don't need a server-client system, I only need an ssh-agent which manages my ssh keys for e.g Git.

Thought I did noticed that after a reboot, the problem does no longer occur and when opening my terminal, the terminal prints "Agent pid ..." on the first line, but it does not save which keys have been stored. All keys which have been stored in the previous session via "ssh-add ~/.ssh/id_rsa" are no longer added to the ssh-agent and have to be re-added.

Offline

#5 2019-11-19 15:21:55

koffeinfriedhof
Member
Registered: 2017-11-30
Posts: 91

Re: Setting up ssh-agent via bashrc

it will be less complicated if you use the ~/.ssh/config-file to fit your needs.

Example:

Host gitserver
Hostname git.mydomain.tld
User gituser
Port 1234
PubKeyAuthentication yes
IdentityFile ~/.ssh/gitKey
ForwardX11 no
IdentitiesOnly yes

Then you can use e.g. "ssh://gituser@gitserver:/path/to.git to access. Hostname, Port and IdentityFile,gituser must be changed to match your requirements.  gitserver is a variable name.

Last edited by koffeinfriedhof (2019-11-19 16:03:02)

Offline

Board footer

Powered by FluxBB