Skip to content

Instantly share code, notes, and snippets.

@octocat
Created July 3, 2014 19:33
Show Gist options
  • Save octocat/2a6851cde24cdaf4b85b to your computer and use it in GitHub Desktop.
Save octocat/2a6851cde24cdaf4b85b to your computer and use it in GitHub Desktop.
# Note: ~/.ssh/environment should not be used, as it
# already has a different purpose in SSH.
env=~/.ssh/agent.env
# Note: Don't bother checking SSH_AGENT_PID. It's not used
# by SSH itself, and it might even be incorrect
# (for example, when using agent-forwarding over SSH).
agent_is_running() {
if [ "$SSH_AUTH_SOCK" ]; then
# ssh-add returns:
# 0 = agent running, has keys
# 1 = agent running, no keys
# 2 = agent not running
# if your keys are not stored in ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub, you'll need
# to paste the proper path after ssh-add
ssh-add -l >/dev/null 2>&1 || [ $? -eq 1 ]
else
false
fi
}
agent_has_keys() {
# if your keys are not stored in ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub, you'll need
# to paste the proper path after ssh-add
ssh-add -l >/dev/null 2>&1
}
agent_load_env() {
. "$env" >/dev/null
}
agent_start() {
(umask 077; ssh-agent >"$env")
. "$env" >/dev/null
}
if ! agent_is_running; then
agent_load_env
fi
# if your keys are not stored in ~/.ssh/id_rsa.pub or ~/.ssh/id_dsa.pub, you'll need
# to paste the proper path after ssh-add
if ! agent_is_running; then
agent_start
ssh-add
elif ! agent_has_keys; then
ssh-add
fi
unset env
@ferguscollins
Copy link

ferguscollins commented Jun 20, 2020

Is this the recommended way to add keys to your agent nowadays or is there new functionality for this?

@01641060604
Copy link

<script src="https://gist.github.com/octocat/2a6851cde24cdaf4b85b.js"></script>

@01641060604
Copy link

@Superleah06
Copy link

Skip to content
Search
user:octocat
Language
8 gist results
1 file
5 forks
1 comment
3 stars
octocat / test.cs
Created 14 years ago

{
#region Adornment Factory
///


/// Establishes an to place the adornment on and exports the
/// that instantiates the adornment on the event of a 's creation
///

1 file
905 forks
255 comments
3341 stars
octocat / .gitignore
Created 12 years ago
Some common .gitignore configurations

Compiled source

###################
*.com
*.class
*.dll
*.exe
*.o
*.so

Packages

1 file
80 forks
18 comments
242 stars
octocat / git-author-rewrite.sh
Last active yesterday
#!/bin/sh

git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
1 file
1 fork
2 comments
2 stars
octocat / test.cs
Created 14 years ago
Module Module1

Sub Main()
    "There it is"
End Sub

End Module
1 file
6 forks
287 comments
19 stars
octocat / hello_world.rb
Created 11 years ago
Hello world!
class HelloWorld
def initialize(name)
@name = name.capitalize
end
def sayHi
puts "Hello #{@name}!"
end
end

hello = HelloWorld.new("World")
1 file
2 forks
3 comments
2 stars
octocat / test.cs
Created 14 years ago
require("./rx");
var child_process = require("child_process");
for (var k in child_process) {
exports[k] = child_process[k];
}
exports.exec = function (command, options) {
var subject = new Rx.AsyncSubject();
var handler = function (err, stdout, stderr) {
if (err !== null) {
subject.OnError(err);
1 file
1 fork
0 comments
1 star
octocat / test.cs
Created 14 years ago
require("./rx");
var fs = require("fs");
for(var k in fs) {
exports[k] = fs[k];
}
exports.rename = function(path1, path2) {
var subject = new Rx.AsyncSubject();
var handler = function(err) {
if (err)
{
1 file
7 forks
4 comments
20 stars
octocat / ssh_key_add.sh
Created 11 years ago

Note: ~/.ssh/environment should not be used, as it

already has a different purpose in SSH.

env=~/.ssh/agent.env

Note: Don't bother checking SSH_AGENT_PID. It's not used

by SSH itself, and it might even be incorrect

(for example, when using agent-forwarding over SSH).

agent_is_running() {
Footer
© 2025 GitHub, Inc.
Footer navigation
Terms
Privacy
Security
Status
Docs
Contact
Manage cookies
Do not share my personal information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment