Doing an ssh-add upon ssh/slogin if key is not in ssh-agent?Why is ssh-add adding duplicate identity keys?Is there a graphical ssh-agent in 10.04 LTS Server?How to get OpenSSH to use ksshaskpass under KDE?ssh-agent is not used when ssh is launched from panel launcher (via `gnome-terminal --command`)Using PKCS#8 encrypted private keys w/ ssh-agentssh-agent running but not working when logged in using PuTTYHow to avoid typing ssh-add everytimeWhy can't I interact with my ssh-agent? (e.g. ssh-add -D doesn't work)Ubuntu 16.04 ssh-add without ssh-agent?Use gnome-keyring as ssh agent instead of openssh

Why is this sentence grammatical?

What was the ultimate objective of The Party in 1984?

Make 2019 with single digits

Assign every word from a line to a variable

How much would a 1 foot tall human weigh?

Where is it? - The Google Earth Challenge Ep. 3

Can a character with good/neutral alignment attune to a sentient magic item with evil alignment?

Why any infinite sequence of real functions can be generated from a finite set through composition?

geschafft or geschaffen? which one is past participle of schaffen?

Are space camera sensors usually round, or square?

International Orange?

Would it be unbalanced to increase a druid's number of uses of Wild Shape based on level?

How do I add Applications to Favorites in Finder' Sidebar?

What is the mathematical notation for rounding a given number to the nearest integer?

Importance of the current postdoc advisor's letter in TT job search

Insight into cavity resonators

Meaning of Swimming their horses

Permutations in Disguise

Masking out non-linear shapes on canvas

Test to know when to use GLM over Linear Regression?

What organs or modifications would be needed for a life biological creature not to require sleep?

Python web-scraper to download table of transistor counts from Wikipedia

Block diagram vs flow chart?

How clean are pets?



Doing an ssh-add upon ssh/slogin if key is not in ssh-agent?


Why is ssh-add adding duplicate identity keys?Is there a graphical ssh-agent in 10.04 LTS Server?How to get OpenSSH to use ksshaskpass under KDE?ssh-agent is not used when ssh is launched from panel launcher (via `gnome-terminal --command`)Using PKCS#8 encrypted private keys w/ ssh-agentssh-agent running but not working when logged in using PuTTYHow to avoid typing ssh-add everytimeWhy can't I interact with my ssh-agent? (e.g. ssh-add -D doesn't work)Ubuntu 16.04 ssh-add without ssh-agent?Use gnome-keyring as ssh agent instead of openssh






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








10















When I'm running Gnome, ssh-agent will run ssh-add upon slogin/ssh if the identity is not loaded. I want to mimic this behavior on remote shells, but everything I find suggests to run ssh-add upon login. I only want to run ssh-add if I subsequently run slogin/ssh on the remote shell, not every time I login.










share|improve this question






























    10















    When I'm running Gnome, ssh-agent will run ssh-add upon slogin/ssh if the identity is not loaded. I want to mimic this behavior on remote shells, but everything I find suggests to run ssh-add upon login. I only want to run ssh-add if I subsequently run slogin/ssh on the remote shell, not every time I login.










    share|improve this question


























      10












      10








      10


      1






      When I'm running Gnome, ssh-agent will run ssh-add upon slogin/ssh if the identity is not loaded. I want to mimic this behavior on remote shells, but everything I find suggests to run ssh-add upon login. I only want to run ssh-add if I subsequently run slogin/ssh on the remote shell, not every time I login.










      share|improve this question














      When I'm running Gnome, ssh-agent will run ssh-add upon slogin/ssh if the identity is not loaded. I want to mimic this behavior on remote shells, but everything I find suggests to run ssh-add upon login. I only want to run ssh-add if I subsequently run slogin/ssh on the remote shell, not every time I login.







      ssh-agent






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 18 '11 at 17:55









      Pete AshdownPete Ashdown

      1,7901 gold badge11 silver badges13 bronze badges




      1,7901 gold badge11 silver badges13 bronze badges























          4 Answers
          4






          active

          oldest

          votes


















          9
















          I worked out a solution for this via the bash shell.



          Add to .bashrc:



          check-ssh-add() 
          if [ "$DESKTOP_SESSION" == "" ]; then
          if [[ `ssh-add -l` != *id_?sa* ]]; then
          ssh-add -t 5h ## 5 hour ssh-agent expiration
          fi
          fi


          slogin()
          check-ssh-add
          /usr/bin/slogin $@


          ssh()
          check-ssh-add
          /usr/bin/ssh $@


          scp()
          check-ssh-add
          /usr/bin/scp $@


          sftp()
          check-ssh-add
          /usr/bin/sftp $@






          share|improve this answer
































            7
















            There's actually an even simpler way. ssh-add -l returns true (0) if there are keys and false (1) otherwise, so your first function can be replaced with this:



            check-ssh-add() 
            if ! ssh-add -l >/dev/null; then
            ssh-add -t 5h
            fi



             






            share|improve this answer


































              1
















              Even simpler in the «this is an interactive session» part add



              ssh-add -l &> /dev/null || ssh-add ~/.ssh/my_id





              share|improve this answer
































                0
















                Newer versions of OpenSSH can add the key to the agent on first use, if you enable AddKeysToAgent yes in your ~/.ssh/config.



                (I've learned this from https://superuser.com/a/1114257/42546. I'm not sure what the proper StackOverflow etiquette is for coping answers across various StackExchange sites.)






                share|improve this answer



























                  Your Answer








                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "89"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );














                  draft saved

                  draft discarded
















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f27014%2fdoing-an-ssh-add-upon-ssh-slogin-if-key-is-not-in-ssh-agent%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  9
















                  I worked out a solution for this via the bash shell.



                  Add to .bashrc:



                  check-ssh-add() 
                  if [ "$DESKTOP_SESSION" == "" ]; then
                  if [[ `ssh-add -l` != *id_?sa* ]]; then
                  ssh-add -t 5h ## 5 hour ssh-agent expiration
                  fi
                  fi


                  slogin()
                  check-ssh-add
                  /usr/bin/slogin $@


                  ssh()
                  check-ssh-add
                  /usr/bin/ssh $@


                  scp()
                  check-ssh-add
                  /usr/bin/scp $@


                  sftp()
                  check-ssh-add
                  /usr/bin/sftp $@






                  share|improve this answer





























                    9
















                    I worked out a solution for this via the bash shell.



                    Add to .bashrc:



                    check-ssh-add() 
                    if [ "$DESKTOP_SESSION" == "" ]; then
                    if [[ `ssh-add -l` != *id_?sa* ]]; then
                    ssh-add -t 5h ## 5 hour ssh-agent expiration
                    fi
                    fi


                    slogin()
                    check-ssh-add
                    /usr/bin/slogin $@


                    ssh()
                    check-ssh-add
                    /usr/bin/ssh $@


                    scp()
                    check-ssh-add
                    /usr/bin/scp $@


                    sftp()
                    check-ssh-add
                    /usr/bin/sftp $@






                    share|improve this answer



























                      9














                      9










                      9









                      I worked out a solution for this via the bash shell.



                      Add to .bashrc:



                      check-ssh-add() 
                      if [ "$DESKTOP_SESSION" == "" ]; then
                      if [[ `ssh-add -l` != *id_?sa* ]]; then
                      ssh-add -t 5h ## 5 hour ssh-agent expiration
                      fi
                      fi


                      slogin()
                      check-ssh-add
                      /usr/bin/slogin $@


                      ssh()
                      check-ssh-add
                      /usr/bin/ssh $@


                      scp()
                      check-ssh-add
                      /usr/bin/scp $@


                      sftp()
                      check-ssh-add
                      /usr/bin/sftp $@






                      share|improve this answer













                      I worked out a solution for this via the bash shell.



                      Add to .bashrc:



                      check-ssh-add() 
                      if [ "$DESKTOP_SESSION" == "" ]; then
                      if [[ `ssh-add -l` != *id_?sa* ]]; then
                      ssh-add -t 5h ## 5 hour ssh-agent expiration
                      fi
                      fi


                      slogin()
                      check-ssh-add
                      /usr/bin/slogin $@


                      ssh()
                      check-ssh-add
                      /usr/bin/ssh $@


                      scp()
                      check-ssh-add
                      /usr/bin/scp $@


                      sftp()
                      check-ssh-add
                      /usr/bin/sftp $@







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Feb 20 '11 at 19:46









                      Pete AshdownPete Ashdown

                      1,7901 gold badge11 silver badges13 bronze badges




                      1,7901 gold badge11 silver badges13 bronze badges


























                          7
















                          There's actually an even simpler way. ssh-add -l returns true (0) if there are keys and false (1) otherwise, so your first function can be replaced with this:



                          check-ssh-add() 
                          if ! ssh-add -l >/dev/null; then
                          ssh-add -t 5h
                          fi



                           






                          share|improve this answer































                            7
















                            There's actually an even simpler way. ssh-add -l returns true (0) if there are keys and false (1) otherwise, so your first function can be replaced with this:



                            check-ssh-add() 
                            if ! ssh-add -l >/dev/null; then
                            ssh-add -t 5h
                            fi



                             






                            share|improve this answer





























                              7














                              7










                              7









                              There's actually an even simpler way. ssh-add -l returns true (0) if there are keys and false (1) otherwise, so your first function can be replaced with this:



                              check-ssh-add() 
                              if ! ssh-add -l >/dev/null; then
                              ssh-add -t 5h
                              fi



                               






                              share|improve this answer















                              There's actually an even simpler way. ssh-add -l returns true (0) if there are keys and false (1) otherwise, so your first function can be replaced with this:



                              check-ssh-add() 
                              if ! ssh-add -l >/dev/null; then
                              ssh-add -t 5h
                              fi



                               







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jan 4 '16 at 9:32









                              HighCommander4

                              1155 bronze badges




                              1155 bronze badges










                              answered Dec 18 '13 at 11:23









                              RelsquiRelsqui

                              711 silver badge2 bronze badges




                              711 silver badge2 bronze badges
























                                  1
















                                  Even simpler in the «this is an interactive session» part add



                                  ssh-add -l &> /dev/null || ssh-add ~/.ssh/my_id





                                  share|improve this answer





























                                    1
















                                    Even simpler in the «this is an interactive session» part add



                                    ssh-add -l &> /dev/null || ssh-add ~/.ssh/my_id





                                    share|improve this answer



























                                      1














                                      1










                                      1









                                      Even simpler in the «this is an interactive session» part add



                                      ssh-add -l &> /dev/null || ssh-add ~/.ssh/my_id





                                      share|improve this answer













                                      Even simpler in the «this is an interactive session» part add



                                      ssh-add -l &> /dev/null || ssh-add ~/.ssh/my_id






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Mar 16 '15 at 14:25









                                      user1458574user1458574

                                      111 bronze badge




                                      111 bronze badge
























                                          0
















                                          Newer versions of OpenSSH can add the key to the agent on first use, if you enable AddKeysToAgent yes in your ~/.ssh/config.



                                          (I've learned this from https://superuser.com/a/1114257/42546. I'm not sure what the proper StackOverflow etiquette is for coping answers across various StackExchange sites.)






                                          share|improve this answer





























                                            0
















                                            Newer versions of OpenSSH can add the key to the agent on first use, if you enable AddKeysToAgent yes in your ~/.ssh/config.



                                            (I've learned this from https://superuser.com/a/1114257/42546. I'm not sure what the proper StackOverflow etiquette is for coping answers across various StackExchange sites.)






                                            share|improve this answer



























                                              0














                                              0










                                              0









                                              Newer versions of OpenSSH can add the key to the agent on first use, if you enable AddKeysToAgent yes in your ~/.ssh/config.



                                              (I've learned this from https://superuser.com/a/1114257/42546. I'm not sure what the proper StackOverflow etiquette is for coping answers across various StackExchange sites.)






                                              share|improve this answer













                                              Newer versions of OpenSSH can add the key to the agent on first use, if you enable AddKeysToAgent yes in your ~/.ssh/config.



                                              (I've learned this from https://superuser.com/a/1114257/42546. I'm not sure what the proper StackOverflow etiquette is for coping answers across various StackExchange sites.)







                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Apr 15 at 11:21









                                              Marius GedminasMarius Gedminas

                                              7,6347 gold badges39 silver badges47 bronze badges




                                              7,6347 gold badges39 silver badges47 bronze badges































                                                  draft saved

                                                  draft discarded















































                                                  Thanks for contributing an answer to Ask Ubuntu!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid


                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.

                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f27014%2fdoing-an-ssh-add-upon-ssh-slogin-if-key-is-not-in-ssh-agent%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Tamil (spriik) Luke uk diar | Nawigatjuun

                                                  Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                                  Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?