- Originally posted at blog.milhamh.dev Prerequisite GitLab account macOS If you want to. Tagged with git, gitlab, macos.
- No, really, how to check if ssh-agent is already running in bash? Answers so far don't appear to answer the original question.
- Some hints about using ssh-agent in ConEmu consoles.
Ssh-agentを起動（または再起動）したい場合、eval $（ssh-agent）を実行して実行する必要のあるいくつかのコマンドが表示されます。もちろん、これはbashまたはcshの構文を提供するため、fishでは失敗します。通信. Using an ssh-agent, or how to type your ssh password once, safely. If you work a lot on linux and use ssh often, you quickly realize that typing your password every time you connect to a remote host gets annoying. Not only that, it is not the best solution in terms of security either.
Enable the SSH server in Windows
You need to add the optional feature ‘OpenSSH Server’ in Windows 10 first by going to
Settings -> search for
Add an optional feature -> search again for
OpenSSH Client and choose to install.
Configure SSH service to automatically start
By default Windows won’t start the
ssh-agent. You can tell Windows to start the service automatically in the future by running the following command in PowerShell (as Administrator).
But right now, manually start the service by running
Generate the key
Open PowerShell and follow these commands to generate SSH key on your machine.
Keep the default location for where to save the key. This should be
Generate a complex password and store in safe place, ideally a password manager.Enter this password when prompted. When complete you’ll be shown the
key fingerprint and the
key's randomart image.
Add key to the SSH Agent
We need to add the key to our ssh-agent so we don’t have to type the key each time we use it.
The agent will recognise that a new key is present and will ask for the passphrase.
Once entered you’ll see the confirmation message
I still needed to manually add the key to the ssh-agent. To do so navigate to the
.ssh folder where we stored our keys earlier
C:Users<username>/.ssh/ and run the following with the correct key name.
This will prompt you to enter the passphrase in and once again you should see the
Identity added confirmation.
Git Check Ssh
Access your public key
Now we have our key we can add it to systems such as GitHub or Bitbucket. To do so follow the instructions for that particular service. We’ll need to retrieve the public key from our machine to do so.
Navigate to the
.ssh folder and find the file
<private-key>.pub. Open this in a text editor. The contents of this file is what you need to copy and paste into the relevant service you’re wanted to add the key to.
Testing the keys
In this example lets assume we’ve added our key to Bitbucket. We can test that the key is correctly set up by running the following command.
If all is well then we should see the
logged in as message without needing to enter the passphrase
Using with Git
By now we have our key correctly stored in the SSH agent and we’re allowed to connect to the Bitbucket servers using SSH. However we might still be prompted to enter our passphrase whenever we try to perform a
git command that talks to the remote.
ssh -T command uses the Windows 10 agent so all appears to be correct, but it won’t behave the same in Git. This is due to the fact Git is using it’s own ssh agent, not the Windows 10 agent that we’ve added our keys to.
We need to tell Git to use the Windows SSH agent instead of it’s own. We do this by updating the
Now when we use Git, we won’t be prompted for our passphrase, even after a restart.
Question – I need to check whether SSH (sshd) is running on my Linux machine. I have a Debian Linux distribution. How can I tell if my OpenSSH server is running?
There are several ways to check whether SSH is running. The sshd daemon is the process that runs the OpenSSH ssh server.
First Check if the process sshd is running:
This will output something like the following if it finds the process called sshd:
So sshd is running with process ID 1399! It is indeed running!
Second, check if the process sshd is listening on port 22:
If ssh is listening on port 22, you will get the following:
So the process with ID 1399 (sshd) is listening on port 22! The second test passed!
Third, you can use the lsof command to check if the port 22 TCP file is open:
So sshd (SSH daemon) and httpd (Apache web server daemon) are both running and listening on the ssh and http ports respectively! Third test passed.
Four, try to telnet to port 22:
If the port is open, you will get the following output:
Check Ssh Agent Keys
If the port number 22 is not open, you will get the following:
Five, check the status of the sshd service:
If you use CentOS or Red Hat:
If you use Debian or Ubuntu (or CentOS or RedHat):
So these were five interesting methods in which you could check if the SSH OpenSSH server is running and listening on port 22. If the process sshd is misbehaving or not listening on port 22, one of these methods will surely fail and you should start or restart sshd using the following command: