22 votes

Running ssh-agent from a shell script

Put the following at the top of your script: eval `ssh-agent` Your script should look like this: #!/bin/bash eval `ssh-agent` ssh-add /path/to/key ... ... Explanation The backticks around ssh-...
scottysseus's user avatar
18 votes
Accepted

ssh - retrieve public key from ssh-agent

man ssh-add will show you all the options available. One of them is ssh-add -L. As the man page says, -L Lists public key parameters of all identities currently repre- sented by the ...
Jenny D's user avatar
  • 27.8k
13 votes
Accepted

In which order does OpenSSH try private keys?

I know about the -v, -vv etc. options, but I'd like to know before I try how ssh is going to behave. There must be a saner method to find out than trial and error. Use the source, Luke! OpenSSH is ...
Jakuje's user avatar
  • 9,785
12 votes

SSH: Permission denied (publickey,gssapi-with-mic,password)

First chmod 700 .ssh and then : chmod 600 .ssh/authorized_keys and test this : restorecon -r -vv .ssh/authorized_keys
Ali Zemani's user avatar
9 votes

Using ssh-agent with KDE?

This is an old question, and probably deserves an updated answer. The following works for me (Fedora 31 / KDE). Set up KWallet with the default wallet (kdewallet) and with the same password as your ...
dhardy's user avatar
  • 191
8 votes

How to prioritize explicit ssh key from commandline over ssh-agent keys?

One workaround is to pass IdentityAgent=none, either on the same commandline: ssh -i /path/to/square.key -o IdentityAgent=none remote.server.net or equivalently, via the ~/.ssh/config: Host remote....
ulidtko's user avatar
  • 438
7 votes

Use a specific forwarded key from SSH-agent?

Nice answer from @Kasperd, but note also that if Host B is compromised, or if you don't trust all those with root privileges there, then you're still exposing all of your keys to abuse for as long as ...
mc0e's user avatar
  • 5,901
7 votes
Accepted

Force the use of a gpg-key as an ssh-key for a given server

I can't do that because my identity is a gpg cardno. You can use IdentityFile and IdentitiesOnly, even with gnupg-provided identities. If you have the card present, export the public key from your ...
anx's user avatar
  • 9,028
6 votes

Running ssh-agent from a shell script

I found this works for me. eval `ssh-agent` # create the process ssh-add ~/.ssh/priv_key # add the key git -C $repo_dir pull # this line is the reason for the ssh-agent eval `ssh-agent -k` # kill the ...
steampowered's user avatar
6 votes
Accepted

How to prioritize explicit ssh key from commandline over ssh-agent keys?

IdentitiesOnly=yes is probably an appropriate option.That is, using only the specified Identities. ssh -i /path/to/square.key -o IdentitiesOnly=yes remote.server.net or Host remote.server.net ...
nelson's user avatar
  • 176
6 votes

Pass password in ssh config

In general most sysadmins would configure things so that their automation does not rely on passwords. SSH For SSH authentication the easiest is to create a key-pair where the private key is not ...
Bob's user avatar
  • 5,825
6 votes
Accepted

SSH Agent forwarding not working on Ubuntu 22.04

This answer helped me solve the same problem: there's some incompatibility between the ssh client shipped with Windows and the server on Ubuntu 22.04. tldr: Installing the most recent release of the ...
kaytwo's user avatar
  • 76
5 votes
Accepted

shell script for running ssh-agent

In order to make your script work, you're going to have to run it with .: . ./ssh_tunnels.sh The . or source command tells bash (YMMV with other shells) to execute the script using the current shell ...
DerfK's user avatar
  • 19.5k
5 votes

Reconnect automatically to a disconnected ssh session

AutoSSH is the tool you want to use for this. It starts the SSH connection and restarts it in case it breaks up.
Tero Kilkanen's user avatar
5 votes
Accepted

How can I use different ssh keys for user1@host and user2@host, without resorting to aliased hostnames?

Check out the Match keyword in your SSH config on the client machine. Specifically, the user and host criteria. The ssh_config(5) man page states (emphasis mine): Match conditions are specified using ...
Wesley's user avatar
  • 32.7k
4 votes

how ssh-agent process is increasing on every login

First of all, are you doing this over an ssh session? If so, then you can use ssh -A [email protected] and don't even use ssh-agent. The -A option will forward your host's ssh-agent to the remote server. ...
wisbucky's user avatar
  • 1,089
4 votes
Accepted

What is the maximum number of private keys you can use via SSH Agent (Pageant)

At last for the ssh-agent, the only limit is about the maximum memory available for the user or process. The keys are stored in the linked list which does not have any effective limit and all the ...
Jakuje's user avatar
  • 9,785
4 votes
Accepted

SSH ignores key in agent and keeps asking for key decryption password

Turns out that, even though only private keys are necessary for connecting to hosts, using ssh-agent requires public keys to work correctly. I guess SSH identifies the keys available in the agent by ...
Jan Warchoł's user avatar
4 votes
Accepted

How to check if SSH agent forwarding is running, from the remote server?

If the variable is not set on server, it means that agent forwarding is not working Forwarding working example. $ echo "$SSH_AUTH_SOCK" # Print out the SSH_AUTH_SOCK variable > /tmp/ssh-...
asktyagi's user avatar
  • 2,860
3 votes
Accepted

How to have multi SSH reverse connections using autossh?

There is no magic here. Only a single application can bind to any one IP:Port tuple at a time. You are binding to 127.0.0.1:XXXX. To connect multiple tunnels, you will either need to maintain mapping ...
EEAA's user avatar
  • 109k
3 votes
Accepted

ssh: Could not resolve hostname add: Name or service not known

ssh -vvv add ~/.ssh/mykey will try to connect to server add and run the ~/.ssh/mykey command. This is obviously not what you want but it certainly explains the error you're getting.
Julie Pelletier's user avatar
3 votes
Accepted

Making ssh agent available in screen after I logout

AFAIK, that isn't going to be possible. The private keys used by the agent are never transmitted to that intermediate server. If your connection to the intermediate server is lost, there is simply ...
Zoredache's user avatar
  • 131k
3 votes

Ansible, Vagrant, sudo and ssh-agent

I think the issue is the /tmp file doesn't have permissions. If you sudo -u root ssh [email protected] That might work since root can read the files To fix this as the vagrant user run setfacl -m ...
Mike's user avatar
  • 22.3k
3 votes

SSH key problems: Not a RSA1 key file unknown key type '-----BEGIN'

Additional information in case anyone finds it useful. This error can be caused by using a private key generated by a recent version of ssh-keygen with a much older version of the ssh client. I ...
Ex Umbris's user avatar
  • 854
3 votes

Force the use of a gpg-key as an ssh-key for a given server

man ssh_config says about IdentityFile: Additionally, any identities represented by the authentication agent will be used for authentication. So it you set IdentityFile /dev/null, that one ...
Andrew Schulman's user avatar
3 votes

Force the use of a gpg-key as an ssh-key for a given server

If your key is stored on some sort of pkcs11 capable hardware such as a smart card you can use ssh directly to access it. CLI -I pkcs11 Specify the PKCS#11 shared library ssh should use to ...
Peter's user avatar
  • 380
3 votes
Accepted

Rewrite / Redirect Host With SSH Config File?

The option you're looking for is CanonicalizeHostname. If you add these to the top of your .ssh/config, ssh internal will try to dns resolve your entry speculatively as internal.example.com, and if ...
Andrew Domaszek's user avatar
3 votes
Accepted

rsync not using the ssh-agent?

You can specify the ssh protocol with rsync using the "-e" option. rsync -e ssh file.tmp example.com:~/ Identity could also be provided in that option. rsync -e "ssh -i ~/.ssh/id_rsa" file.tmp ...
saf's user avatar
  • 171
3 votes

Does SSH allow jump host to access forwarded agent?

No, the jump host will not have access to the agent. According to the man page: Note also that the configuration for the destination host (either supplied via the command-line or the configuration ...
Lacek's user avatar
  • 7,278
2 votes

Reverse ssh-agent forwarding. Using a remote ssh key

Since OpenSSH 6.7 (2014-10-06), there is an option to achieve the goal of reverse ssh-agent forwarding. The feature is Unix domain socket forwarding. Example: export SSH_AUTH_SOCK=~/.ssh/ssh-agent....
fungus's user avatar
  • 21

Only top scored, non community-wiki answers of a minimum length are eligible