Many developers use good OpenSSH as a substitute for old telnet and rsh commands. OpenSSH is not only secure but also encrypted. One of the more attractive features of OpenSSH is that it can use RSA and DSA authentication protocols based on a pair of complementary digital "keys" to authenticate users. The RSA and DSA authentication commitment does not require a password.
Many developers use good OpenSSH as an old te
LnEt and rsh
CommandOpenSSH is not only secure but also encrypted. One of the more attractive features of OpenSSH is that it can use RSA and DSA authentication protocols based on a pair of complementary digital "keys" to authenticate users. RSA and DSA certification commitment
No Password requiredThe ability to establish connections with remote systems is one of its main charms. In the second article, Daniel introduced
ssh-agent
(Private Key cache) and
keychain
The design of this special bash script makes key-based authentication extremely convenient and flexible.
Introduction to ssh-agent
ssh-agent
It is a special program designed to process RSA and DSA keys happily and securely, it is included in the OpenSSH distribution (see section 1st of this series for an introduction to RSA and DSA authentication ). Different fromssh
,ssh-agent
Daemon is a daemon that has been running for a long time. It is designed to cache the decrypted private key at high speed.
ssh
The built-in support is allowed to be the samessh-agent
Communication, allowssh
You do not need to prompt you for a password to obtain the private key for decryption every time you connect to a new connection. Forssh-agent
, You only need to usessh-add
Add a private keyssh-agent
. This is a one-time process; usedssh-add
After,ssh
Tossh-agent
Get your private key without prompting you for a phrase.
Use ssh-agent
Let's take a look at the wholessh-agent
The working process of the key cache system.ssh-agent
At startup, it will output some important environment variables before it leaves the shell and continues running in the background. Below isssh-agent
Some examples of output generated at the beginning:
% ssh-agentSSH_AUTH_SOCK=/tmp/ssh-XX4LkMJS/agent.26916; export SSH_AUTH_SOCK;SSH_AGENT_PID=26917; export SSH_AGENT_PID;echo Agent pid 26917;
|
As you can see, in factssh-agent
If these commands are executed, two environment variables are set: SSH_AUTH_SOCK and SSH_AGENT_PID. The export command is included to make these environment variables available for any additional commands that will be run later. Well,IfShell calculates these rows, but at this time they are printed to the standard output (stdout. We can callssh-agent
:
Run bash first.ssh-agent
Afterssh-agent
. Shell sets and exports the SSH_AGENT_PID and SSH_AUTH_SOCK variables in this call method (using reverse quotation marks instead of regular single quotes) so that these variables are available for all new processes that are started during the login session.
Startssh-agent
The best way is to add the above line to your ~ /. Bash_proFileIn this way, all programs started in your login shell will see the environment variables, and can locatessh-agent
, And query the key for it as needed. The most important environment variable is SSH_AUTH_SOCK; SSH_AUTH_SOCK containsssh
Andscp
Can be used in the same wayssh-agent
The path of the UNIX domain socket for the conversation.
Use ssh-add
Howeverssh-agent
The cache is empty at startup, and there is no private key for decryption. We can usessh-agent
Before that, you must first usessh-add
Command to add our private keyssh-agent
. In the following examplessh-add
Put my ~ /. Add a private RSA key for ssh/identityssh-agent
In the cache:
# ssh-add ~/.ssh/identityNeed passphrase for /home/drobbins/.ssh/identityEnter passphrase for /home/drobbins/.ssh/identity (enter passphrase)
|
As you can see,ssh-add
Ask for my key phrase to decrypt the private key and store it inssh-agent
Cache for use. Once you have usedssh-add
Add a private key (or multiple keys)ssh-agent
In the cache,AndIn the current shell (if you ~ /. Start In bash_profilessh-agent
) Define SSH_AUTH_SOCK, then you can usescp
Andssh
Establish a connection with a remote system without providing a password phrase.
Limitations of ssh-agent
ssh-agent
It is really good, but its default configuration will leave us some small inconvenience. Let's take a look at these shortcomings.
First ,~ In/. bash_profileeval `ssh-agent`
Enable a newssh-agent
Replicas. This is not just a waste, but also means you have to usessh-add
Tossh-agent
Add a private key to the copy. If you only want to open a terminal or console on the system, this is no big deal, but most of us open a lot of terminals. Every time you open the console, you need to enter a password phrase. From a technical point of view, sincessh-agent
The process should be enough. If we still need to do so, it is unreasonable.
Relatedssh-agent
Is not compatible with cron jobs. Since cron jobs are started by the cron process, these jobs cannot inherit the SSH_AUTH_SOCK variable from their environments, so they cannot be known.ssh-agent
The process is running and how to contact it. It turns out that this problem can also be fixed.