Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore file for ssh directory

Tags:

git

gitignore

ssh

I am trying to make sure the contents of the .ssh directory do not get into the Git Repository:

executeS:~$ git diff --stat --cached origin/master

.gitignore           |   7 ------
 .ssh/.gitignore      |   2 ++
 .ssh/authorized_keys |   1 +
 .ssh/id_rsa          |  51 ++++++++++++++++++++++++++++++++++++++
 .ssh/id_rsa.pub      |   1 +
 .ssh/known_hosts     |   2 ++
 .viminfo             | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------

I then take them out as follows:

executeS:~$ git rm --cached .ssh/authorized_keys
rm '.ssh/authorized_keys'
executeS:~$ git rm --cached .ssh/id_rsa
rm '.ssh/id_rsa'
executeS:~$ git rm --cached .ssh/id_rsa.pub
rm '.ssh/id_rsa.pub'
executeS:~$ git rm --cached .ssh/known_hosts

I have the following .gitignore file

executeS:~/.ssh$ pwd
/home/dockcclubdjango/.ssh

executeS:~/.ssh$ cat .gitignore
.*
!/.gitignore

But then if I do, "git add . -A", I get waht I had in step 1 all over again. What can I do to make sure that .ssh NEVER gets into the repository?

like image 395
Casey Harrils Avatar asked Feb 14 '26 14:02

Casey Harrils


1 Answers

You need also

  1. add /.ssh line to your .gitignore
  2. commit all changes (removal of .ssh from git and addition of the line to .gitignore)

Now git add -A will not add it back (tested with Git 2.15.0)

Regarding second question ("What can I do to make sure that .ssh NEVER gets into the repository?"): .gitignore does not prevent a file to be added to a repository. You can always add ignored file with git add -f path/to/file.

like image 137
Piotr Findeisen Avatar answered Feb 17 '26 06:02

Piotr Findeisen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!