How to find Private Key Location - ssh

I'm trying to access a server using Filezilla and was told I needed to use authentication with public/private keys. I created the keys using the Terminal, but cannot find them on my computer.
This is where the key is located:
(/Users/ed/.ssh/id_rsa)
I checked in my home directory, but the folder .ssh is nowhere to be found. Is there a secret place .ssh folder is stored and how can I access it?
My Mac runs on OS X ElCaptain. I would really appreciate any help.

Files and folders starting with a period (.ssh) are hidden by default. To find private/public key, run this commands:
ls -a
In your case, run this commands to find the ssh keys:
cd ~/.ssh
then:
ls -a
Now you should see the keys like this:
. .. id_rsa id_rsa.pub
If the keys are not there then definitely you need to create the key by ssh-keygen command.

(MacOS) I my case, .ssh folder was hidden so I went to folder route (example /Users/syed.dastagir)and pressed Command + Shift + . (full stop/period) and it showed me .ssh folder.
When you no longer want to see the hidden folders just press Command + Shift + . again.

If using Finder, I used defaults
Terminal
write com.apple.Finder AppleShowAllFiles true [Press Return]
killall Finder
Then I was able to see .ssh directory in Finder at
/Users/MYUSERNAME/.ssh

when referencing the private key name, when setting up the config file for GitHub for example ( https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent ), I thought I needed an id with number, i.e 'id_43248390', however I just needed to reference 'id_rsa'.
This is incase any gets blocked similarly.

Related

Copying ssh key from windows machine to windows server 2019

I've been trying to get access to Windows Server 2019 without password through OpenSSH protocol.
So I've created new key which I need it to be copied to the Windows Server, I've tried this:
ssh-copy-id -i ~/.ssh/id_rsa user#server
But I get this after entering correct password:
'exec' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified.
The system cannot find the path specified.
My issue is how to transfer key from one windows machine(using gitbash, WSL, powershell or whatever)
to Windows Server 2019 location of authorized keys if I am not mistaken.
I am desperate enough to do it manually but location of those keys is mystery to me, do I need to set something on Windows Server first so that it can accept keys for authentication ?
What is the alternative on ssh-copy-id from Windows machine to Windows Server 2019 ?
Found solution:
Followed this helpful youtube guide, props to the
https://www.youtube.com/watch?v=Cs3wBl_mMH0&ab_channel=IT%2FOpsTalk-Deprecated-SeeChannelDescription
Also, installing OpenSSHUtils worked with:
Install-Module -Name OpenSSHUtils -RequiredVersion 0.0.2.0 -Scope AllUsers
Also this guide helped:
https://www.cloudsma.com/2018/03/installing-powershell-modules-on/
My server didn't have access so I manually copied file from:
C:\Program Files\WindowsPowerShell\Modules to the server's:
Server:\Program Files\WindowsPowerShell\Modules
First, this error message is followed by microsoft/vscode-remote-release issue 25
Current workaround (the context is VSCode, but should apply also for regular SSH connection):
Also, for anyone else here that loves their bash on windows but still wants to be able to use VSCode remote, the workaround I have currently setup is to use an autorun.cmd deployed on the servers that detects when an SSH connection is coming in and has a terminal allocated:
#echo off
if defined SSH_CLIENT (
:: check if we've got a terminal hooked up; if not, don't run bash.exe
C:\cygwin\bin\bash.exe -c "if [ -t 1 ]; then exit 1; fi"
if errorlevel 1 (
C:\cygwin\bin\bash.exe --login
exit
)
)
This is known to work with Cygwin bash, unsure about bash that ships with windows; I imagine it's very sensitive to how the TTY code works internally.
This way, launching cmd.exe works normally, using VSCode (because it does not allocate a PTY) works normally, but SSH'ing into the machine launches bash.exe.
I suspect it would also work using the bash.exe which comes with Git for Windows, should it be installed on the target server.
The destination file should be on the server:
%USERPROFILE%\.ssh\authorized_keys
If you can do it manually, simply try and scp it instead of using ssh-copy-id
scp user#server:C:/Users/<user>/.ssh/authorized_key authorized_key
# manual and local edit to add the public key
scp authorized_key user#server:C:/Users/<user>/.ssh/authorized_key
(again, I would use the scp.exe coming with Git For Windows, installed this time locally)
Found solution:
Followed this helpful youtube guide, props to the
https://www.youtube.com/watch?v=Cs3wBl_mMH0&ab_channel=IT%2FOpsTalk-Deprecated-SeeChannelDescription
Also, installing OpenSSHUtils worked with:
Install-Module -Name OpenSSHUtils -RequiredVersion 0.0.2.0 -Scope AllUsers
Also this guide helped:
https://www.cloudsma.com/2018/03/installing-powershell-modules-on/
My server didn't have access so I manually copied file from:
C:\Program Files\WindowsPowerShell\Modules to the server's:
Server:\Program Files\WindowsPowerShell\Modules

How to add ssh key to project in GCP

I am trying to add my public ssh-key to my project but can't seem to make it work.
According to documentation : https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys?hl=fr#project-wide ; after creating my ssh txt file I need to use the command :
gcloud compute project-info add-metadata --metadata-from-file ssh-keys=[LIST_PATH]
I named my ssh txt file "ssh.txt" and my full path was to file was : C:\Users\33768\Desktop\ssh.txt .
I tried the following commands :
gcloud compute project-info add-metadata --metadata-from-file ssh-keys=C:\Users\33768\Desktop\ssh.txt
gcloud compute project-info add-metadata --metadata-from-file ssh-keys="C:\Users\33768\Desktop\ssh.txt"
gcloud compute project-info add-metadata --metadata-from-file ssh-keys=C:/Users/33768/Desktop/ssh.txt
gcloud compute project-info add-metadata --metadata-from-file ssh-keys="C:/Users/33768/Desktop/ssh.txt"
Yet, none of them worked, error being :
ERROR: (gcloud.compute.project-info.add-metadata) Unable to read file [LIST_PATH]: [Errno 2] No such file or directory: [LIST_PATH]
where I replaced the actual list path that command line tool showed by [LIST_PATH].
Please someone help, I am getting crazy.
Thx.
Thanks everyone.
I actually found why it was not working. I used ubuntu for windows and that messed up the path of my folders. Inside the ubuntu terminal, I do not have access to folder in my local machine that are not on my ubuntu folder.
Just ran my commands outside of ubuntu terminal and it worked !
From your post I see you use Windows. I don't know how you generate your keys so I will write down everything starting from this procedure.
Download Putty (it also includes PuttyGen). Run PuttyGen, change "comment" field to your username#somemachine and click "Generate" button. After some "mouse moving" you will get your personal SSH-key which looks something like this:
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAtJqgJA1MLB7ZqIL+xF0cnZaXyGW9LYxlyj/JrK/eOkgvRN36zI7xJc1ML5uO2Hn+EPiTwKO5+0xmwomZKnu2nrCsuZzQZakGWHiyKBYSQ1x+l+PqISOniiHOGTHc0p//lwbCLKO7bUUYuS2+7Uw3lNhKytnNA7WbcfMmm+NTH2C8ZdWptWaGmX/Yt1kdUKFCyTLAlXqdoNyr4QssdaMo4BY07JUrYHGN8Uzt7/Knd6zqqsK4Hzf0lTzxYdiuP3Y6qYBcAMtLs7iaEibu8r/i1Js7DpSHQTUYbQ6lWBk7p1yI8XJ809FTXLy20doF3ElQjBrqk/dkDk1p3AV2RlplYQ== username#somemachine
Click "save public key" and save it on some directory. After that "save private key" - ideally to the same directory.
You have your keys generated and saved.
Now - add them to your GCP project. Easiest ways are:
console - go to Compute Engine > Metadata > SSH Keys - click "Edit" button and then "Add item". Copy your entire SSH key string into this box and click "save".
gcloud SDK - gcloud compute project-info add-metadata --metadata-from-file ssh-keys=your_file_name/name/and/path - when adding you might get a warning The following key(s) are missing the <username> at the front - don't worry - they will still work.
If in doubt just read the documentation how to add private SSH-keys to your GCP project. It's a bit long but everythin's explained in detail.
Furthermore - I generated keys on Linux, added them the same way to my project and it also works.
#John Hanley: [LIST_PATH], or ssh.txt in this case, is the concatenation in a single file of all the public keys (.pub) to upload as metadata.

ls doesn't show any output in ssh connected to an Debian 9 VM instance in Google Cloud Platform

this might be a dumb question, but I checked everywhere and there's no direct answer to it.
I set up both SSH keys successfully and I can connect to my instance via terminal, but when I do "ls", it doesn't show me any output. I am using iTerm2 with zsh on my Mac but I don't think this is an issue.
Can anybody give me a hint? Thanks!
When you access a VM through SSH, your working directory is the home directory of the user specified with the SSH command, i.e. /home/username. In case you access as root, the working directory will be /root.
You can check it through the command pwd
If it is a brand new machine, it is normal that the output of 'ls' is empty since in your home directory no file matches the filters of 'ls' with no parameters. The reason is that 'ls' doesn't show filenames starting with a dot ('.') because in the Linux convention they are hidden unless you run ls -al.
You can try again with $ ls -al and you will be able to see hidden files and directories as well.
On the other hand you can create as well first an empty file and then running again 'ls':
$ touch file
$ ls

Where to store the ssh public key for connecting GitLab to Bitbucket?

I'd like to connect (an Omnibus install of) GitLab to Bitbucket. According to the documentation, I need to create and store a public key for it:
GitLab will automatically register your public key with Bitbucket as a
deploy key for the repositories to be imported. Your public key needs
to be at ~/.ssh/bitbucket_rsa.pub, which will expand to
/home/git/.ssh/bitbucket_rsa.pub in most configurations.
The fact is I don't have a /home/git. How could I know, then, where I must create the public key, so that GitLab notices it and registers it automatically?
The home directory for the git User in an Omnibus install is by default /var/opt/gitlab. You can either check your gitlab.rb config file for the key user['home'] and see if you have modified it or do a cat /etc/passwdand find the home diretory for the user git there.
Default value user['home'](remember the # means it is commented out):
# user['home'] = "/var/opt/gitlab"
Output of cat /etc/passwd | grep git:
git:x:1000:1000:git,,,:/var/opt/gitlab:/bin/sh
Once you have found out where the home directory for the user git is, you can put bitbucket_rsa.pub in the folder .ssh. If it doesn't exist you can create that folder.

PSCP copy files from godaddy to my windows machine

I want to take backup of my website which is hosted on godaddy.
I used pscp command from my windows dos and try to download whole public_html folder.
my command is :
pscp -r user#host:public_html/ d:\sites\;
Files are downloading properly and folders also. But the issue is public_html and other subfolders has two folder like "./" and "../". Due to these two folders my copy is getting failed and I am getting
"security violation: remote host attempted to write to " a '.' or '..' path!"error.
Hope any one can help for this.
Note : I have only ssh access and have to download it from ssh commands itself.
Appending a star to the source should fix it, e.g.
pscp -r user#host:public_html/* d:\sites\;
Also you can do same thing by not adding '/' at the end of your source path.
For eg.
pscp -r user#host:public_html d:\sites
Above command will create public_html directory if not exists at your destination (i.e. d:\sites).
Simply we can say using above command we can make a as it is clone of public_html at d:\sites.
One important thing: You need to define the port number over here "-P 22".
pscp -r -P 22 user#host:public_html/* D:\sites
In my case, it works when I use port number 22 with the above script.