From 3d6de6bf4be3a79ca257e25871dd8924376705c2 Mon Sep 17 00:00:00 2001 From: Jonas Forsberg Date: Sun, 14 Nov 2021 11:41:50 +0100 Subject: [PATCH] created ssh-agent user systemd unit ssh-agent is now a user systemd unit and added ./ssh/config to dotfiles --- .bashrc | 22 +++++++++++++------ .../default.target.wants/ssh-agent.service | 1 + .config/systemd/user/ssh-agent.service | 10 +++++++++ .ssh/config | 1 + .ssh/config.d/common | 1 + 5 files changed, 28 insertions(+), 7 deletions(-) create mode 120000 .config/systemd/user/default.target.wants/ssh-agent.service create mode 100644 .config/systemd/user/ssh-agent.service create mode 100644 .ssh/config create mode 100644 .ssh/config.d/common diff --git a/.bashrc b/.bashrc index d9458c4..0905b9b 100644 --- a/.bashrc +++ b/.bashrc @@ -4,6 +4,21 @@ export HISTSIZE=-1 export HISTFILESIZE=-1 export EDITOR="vim" +# used by systemd user unit file ssh-agent in ~/.config/systemd/user/ssh-agent.service +#[Unit] +#Description=SSH key agent +# +#[Service] +#Type=simple +#Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket +#ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK +# +#[Install] +#WantedBy=default.target +# +#Also add "AddKeysToAgent yes" to ~/.ssh/config +export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket" + test -s ~/.alias && . ~/.alias || true export PATH=~/bin:~/.local/bin:"$PATH" type go >/dev/null 2>&1 && export GOPATH=$(go env GOPATH) && export PATH="$PATH":$GOPATH/bin @@ -13,13 +28,6 @@ GPG_TTY=$(tty) export GPG_TTY export PWHOME="$HOME/Nextcloud/passwords" -#make sure we only run one 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 if [[ -d "$HOME"/.bash_completions.d ]];then for file in "$HOME"/.bash_completions.d/*.sh;do diff --git a/.config/systemd/user/default.target.wants/ssh-agent.service b/.config/systemd/user/default.target.wants/ssh-agent.service new file mode 120000 index 0000000..03a1427 --- /dev/null +++ b/.config/systemd/user/default.target.wants/ssh-agent.service @@ -0,0 +1 @@ +/home/jonas/.config/systemd/user/ssh-agent.service \ No newline at end of file diff --git a/.config/systemd/user/ssh-agent.service b/.config/systemd/user/ssh-agent.service new file mode 100644 index 0000000..9428410 --- /dev/null +++ b/.config/systemd/user/ssh-agent.service @@ -0,0 +1,10 @@ +[Unit] +Description=SSH key agent + +[Service] +Type=simple +Environment=SSH_AUTH_SOCK=%t/ssh-agent.socket +ExecStart=/usr/bin/ssh-agent -D -a $SSH_AUTH_SOCK + +[Install] +WantedBy=default.target diff --git a/.ssh/config b/.ssh/config new file mode 100644 index 0000000..53eda29 --- /dev/null +++ b/.ssh/config @@ -0,0 +1 @@ +Include config.d/* diff --git a/.ssh/config.d/common b/.ssh/config.d/common new file mode 100644 index 0000000..b1425ef --- /dev/null +++ b/.ssh/config.d/common @@ -0,0 +1 @@ +AddKeysToAgent yes