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-...
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 ...
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 ...
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
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 ...
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....
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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 ...
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.
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 ...
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. ...
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 ...
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 ...
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-...
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 ...
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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....
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
ssh-agent × 145ssh × 122
ssh-keys × 44
linux × 18
ubuntu × 18
ssh-tunnel × 12
bash × 7
git × 6
ssh-keygen × 6
windows × 5
mac-osx × 4
authentication × 4
sudo × 4
putty × 4
centos × 3
cron × 3
rsync × 3
ansible × 3
shell × 3
jenkins × 3
forwarding × 3
scp × 3
cygwin × 3
gpg × 3
sshfs × 3