last day (15 days later) » 

11:13 AM
0
Q: Adding SSH key to ssh-agent

Paras KhoslaI am learning Git and Github. I am trying to push few changes onto the Github server. I have generated the SSH key and also added the public key on Github. I am not however able to add it to the ssh-agent. I tried following the instructions as mentioned here, but the terminal displays the followi...

 
Does the ~/.ssh/ directory exist?
 
@mkrieger1 I cannot seem to find it. But then shouldn't the "touch ~/.ssh/config" command create that file?
 
hcp
Try running ls -a in the Users/paraskhosla to see if you have the .ssh folder.
 
@hcp Thanks. I did that, the folder is missing.
 
hcp
great! so, did you set up any ssh keys yet? if you didnt, the ssh-agent will set up the folder for you.
 
11:13 AM
@hcp Yes I did. I have saved that one public key on Github as well.
 
hcp
hmmm, thats weird, where is your ssh key then?
 
@hcp I can even see the key and key.pub on the VS Code sidebar. I was following this tutorial exactly, don't know what went wrong.
 
hcp
what folder are you in (in vscode)?
 
@hcp I am working on test-repo repository under Test-Git folder.
 
hcp
and you can see that your keys are in this folder?
oh great, I see your update now
so, what I would do is, move both these keys to the .ssh folder. (if the folder doenst exist, create it under Users/paraskhosla with mkdir or with mac GUI)
with that done, in the .ssh folder create the config file with nano ~/.ssh/config file and then you can keep following the video tutorial, from minute 24:15.
The problem here is that you somehow created the ssh keys in the folder you are curently in, instead you should have created them in you .ssh folder.
 
11:13 AM
@hcp Might I also ask, what command would I use if I was to create the folder using the terminal?
 
hcp
sure, I would go for mkdir Users/paraskhosla/.ssh
 
@hcp I get this error: mkdir: Users/paraskhosla: No such file or directory
 
hcp
sorry, my mistake, mkdir /User/paraskhosla/.ssh
 
@hcp No, it does not create the file. Again I got the same error.
 
hcp
what does pwd return you?
 
11:13 AM
@hcp /Users/paraskhosla
 
hcp
so, copy this and run mkdir <copied>/.ssh
 
@hcp That does do the needful.
@hcp How would I shift the key and key.pub files to this directory now?
 
hcp
exactly, thats what you need to do now.
 
@hcp Since I cannot 'see' this directory, I'm using Apple Silicon, so how would I go about doing that?
 
hcp
so, I would use the mv command but I don't remember well how to use it. I know that its something like mv <source> <destination> so it would be for sure something like mv <folderwherethekeysare>/key.pub ~/.ssh and you would also need to do the same for the key file.
 
11:13 AM
@hcp That completed the shifting of the files. Thanks.
 
hcp
hope that was helpful :)
 
You should change the mode of the .ssh folder to 0700 or rwx------, using chmod 700 ~/.ssh. This doesn't really matter if your laptop is private and doesn't have any other users, but it will make any extra checking that ssh performs happier that the folder is protected against other users.
Note that on macOS, when you open a Terminal window, the ssh agent is already running (it is started at the time you log in to macOS) and therefore you should not run eval "$(ssh-agent -s)". Things are different on some Linux systems, where you should run the eval. The details vary from one Linux to another.
 
@torek Even though I created the file /.ssh/config using the mkdir Users/paraskhosla/.ssh/config command, I cannot 'see' this file and also I cannot seem to write on this file.
 
If you literally ran mkdir Users/paraskhosla/.ssh/config, this is wrong. You wanted to make the .ssh folder, and then make a file named config in the .ssh folder. This mkdir would attempt to make a folder named config. The path is also incorrect as it requires a leading slash: paths are relative to the current working directory when they do not start with slash, and relative to the root directory when they do start with slash, and /Users is in the root directory, not the current directory.
In any case, files and folders whose name starts with a dot . are hidden by default, so that you do not see them cluttering up your work areas. That's why Git repositories are stored in .git, so that you don't see them: you see only your working-tree files. To see them with ls, use the -a or -A flag (-a shows you . and .. as well as other dot-names; -A omits the . and .. entries). To see them in Finder, check the "show hidden" checkbox I think (I never use Finder for this and forget how the show-hidden works).
 
@torek So how would I go about reversing this operation, i.e., deleting the config folder and at the same time retrieve the key and key.pub files?
 
11:13 AM
rmdir <folder> will remove a folder if and only if it is empty (other than . and .., the automatic entries the OS uses to move around with). If it's not empty, move the files out of it, then rmdir it.
 
@ParasKhosla Did you resolved your issue?
 

last day (15 days later) »