How to run an interactive script at KDE Plasma 5 startup?
How to add ssh keys to ssh agent?
KDE Plasma 5 allows to set startup scripts, see How to autostart programs on KDE Plasma 5.
I want to add my ssh keys at every startup to the ssh agent. However, the keys are encrypted and adding them to the agent requires a password. I need to type the password.
How to do it:
- Save the script below into your home directory as
init_env.sh
- Set the executable bit of the script file, e.g.
chmod 755 init_env.sh
- Install as startup script in KDE
- Open KDE
System Settings
- Click
Startup and Shutdown
icon - Change to planel
Autostart
- Click on
Add Script…
button - Choose
init_env.sh
- Enable
Create as symlink
- Open KDE
- Reboot and test
init_env.sh
#!/bin/bash
# no parameters -> open konsole window
if test $# -eq 0; then
# wait a little bit
sleep 15
# call itself with parameter in a konsole executing bash with command
konsole --workdir "$HOME" -e bash -c "$HOME/init_env.sh -i"
# parameters -> execute init steps
else
# add id_rsa key to ssh agent if not added yet
if ! ssh-add -l | grep id_rsa; then
ssh-add ~/.ssh/id_rsa
fi
fi