can not load private key using ssh-add - macos

I tried to create a ssh key by doing following command:
ssh-keygen -t dsa
then it prompts me to enter store path:
Enter file in which to save the key (/Users/KesongXie/.ssh/id_dsa): id_dsa
after I entering my passphrase, i got the following result
Your identification has been saved in id_dsa.
Your public key has been saved in id_dsa.pub.
Then i tried to load my private ssh key using the followibg command
ssh-add /Users/KesongXie/.ssh/id_dsa
It shows the result:
-bash: ssh-add/Users/KesongXie/.ssh/id_dsa: No such file or directory
When I navigate to my local diretory, Users/KesongXie, and I can not find the .ssh file(as expected , doc files are hidden ), but when I tried to view it in my terminal, I type
cd ~
pwd
I got Users/KesongXie
and i tired to ls and expect to see my .ssh, but it's still invisible. then i tried to
cd .ssh
I found out i then entered the .ssh directory, use ls , i can see the following result:
github_rsa github_rsa.pub id_dsa id_dsa.pub known_hosts
the keys do store in the .ssh folder , but i wonder why i can not load the private key using
ssh-add /Users/KesongXie/.ssh/id_dsa

If I read this correctly, you did:
Enter file in which to save the key (/Users/KesongXie/.ssh/id_dsa): id_dsa
This tells the ssh-keygen command to make an id_dsa file in the current directory. To make one in the .ssh directory, you have to simply press enter.
So now you have key files in your home directory, and you don't have a .ssh directory (at least that is what I suspect is happening)
The "cd .ssh" command will do nothing because you don't have a .ssh directory. That's why other programs complain the file does not exits.
By the way, the ls command will not show you any files that start with a dot, like ".ssh", because those files are hidden. Use "ls -a" to see hidden files.

Related

keep getting error /Users/newuser/.ssh/id_rsa: No such file or directory when trying to connect to ssh agent. Any idea what Im doing wrong?

I'm following the github instructions on how to set up ssh key and add it to the ssh agent. However after I input ssh-add -K ~/.ssh/id_rsa into the terminal, I receive this error: /Users/newuser/.ssh/id_rsa: No such file or directory
I set up my ssh key using Enter file in which to save the key (/Users/newuser/.ssh/id_rsa) so I believe its the correct name.
Any help would be appreciated!
I have been following the same instructions and meet the same problem. This is what worked for me:
cd ~/.ssh
ssh-add id_rsa
Enter file in which to save the key (/c/Users/YOURNAME/.ssh/id_rsa): id_rsa
Use the key in id_rsa.pub to add SSH Key
$ ssh -vT git#github.com
Screen will display:
You've successfully authenticated, but GitHub does not provide shell access.

On windows, could not create directory '/home/<username>/.ssh'

To configure git on windows with gitbash, (as explained here):
I generated a ssh key with ssh-keygen -t rsa -b 4096 -C "your_email#example.com" at /c/Users/my-username/.ssh.
then, added the ssh key to ssh-agent with ssh-add ~/.ssh/id_rsa
The problem is now, every-time I try to connect to github via ssh, there is an error message with a reference to a wrong location:
Could not create directory '/home/my-username/.ssh'.
How to fix this?
Things I tried:
I checked in the env variable and in C:/Program Files/Git/etc/ssh/ssh_config, but didn't find anything…
And I set the HOME environment variable pointing to %USERPROFILE% for ssh to pick it up with setx HOME %USERPROFILE%.
In this answer, someone having the same problem with cygwin, modified a file in cygwin to fix the problem. Is there something similar in my case?

Execute command inside a shell script on a remote machine and get output on local machine

There are similar questions on stackoverflow, but they either don't have an answer or use some language (C#, Python, ...). I'm trying to execute a command on a remote machine using ssh and get the console output back to the local machine. Below is the command I'm having issues:
sshpass -p $password 'find /home/pi/Transmission_Downloads/ -type f \( -iname "*.mp4" -o -iname "*.mkv" -o -iname "*.avi" \) -newermt "2016-02-01"' user#myserver.com
When I try to execute it inside my script I get "sshpass: Failed to run command: No such file or directory" error.
What I'm trying to achieve: fetch from the server a list of new files downloaded (movies and TV shows) for later on pulling them from the server using rsync.
Is there a way I can achieve this using only password, or do I HAVE TO use public/private keys to access the server?
My local machine is using Ubuntu 14.04 (desktop) and my server is running Raspbian.
Setting up a password less login to your remote machine might be a solution for easily accomplishing the task.
First log in on Sys_A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a#Sys_A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a#A
Now use ssh to create a directory ~/.ssh as user b on Sys_B. (The directory may already exist, which is fine):
a#Sys_A:~> ssh b#B mkdir -p .ssh
b#Sys_B's password:
Finally append a's new public key to b#Sys_B:.ssh/authorized_keys and enter b's password one last time:
a#Sys_A:~> cat .ssh/id_rsa.pub | ssh b#B 'cat >> .ssh/authorized_keys'
b#Sys_B's password:
From now on you can log into Sys_B as b from Sys_A as a without password:
a#Sys_A:~> ssh b#Sys_B
Then you can integrate your command in a bash script, and use ssh without any user interaction.

Mac Terminal Keeps Asking for Password When Using PPK with SSH

I am attempting to connect to an Amazon EC2 Server via Mac Terminal. I have a PPK file that does not have a password attached to it, but when I try to connect I get a popup box that says "Enter the password for the SSH Private Key."
So we tried creating a PPK that has a password - but it does not accept the password, it still rejects the connection.
I have a Windows user who is able to connect using the same PPK on Putty.
Has anyone experienced this issue?
The mac is looking for a .pem key. The ppk is generated specifically for putty. If you don't have the original ppk key.
Download puttygen.exe from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html Then go to conversions -> export OpenSSH key. Save the output as a .pem file and try using that with the mac.
If this doesn't work can you post the command you're running from mac. Its possible you've got some extra parameter or something.
Maybe your problem is with permissions for your key. I know in linux its required to change the permissions.
Taken from the website http://om4.com.au/ssh-rsa-key-pairs-passphrases-leopard/
Clear the contents of your ~/.ssh directory and set the directory permissions to 700 (directories need to be "executable")
$ rm ~/.ssh/*
$ chmod 700 ~/.ssh
Generate your rsa key pair (there are variations for this, but this is the version I used):
$ ssh-keygen -t rsa
Set the permissions for all files in ~/.ssh to 600
$ chmod 600 ~/.ssh
Copy your id_rsa.pub key to your server’s .ssh/authorized_keys file
Add your passphrase to your keychain using this command:
$ ssh-add -K
(you will see Enter passphrase for [your system]/.ssh/id_rsa: )
The error Enter your password for the SSH key x can result from using a key of the wrong format (such as a ppk key) in ssh or sftp. This is because it is interpreted as an encrypted ssh key and so prompts for the passphrase, when actually there is no passphrase.
In OS X I was able to simulate this error by simply typing the following into the command line:
sftp -o IdentityFile=randomtextfile mysftpserver.com
The solution is to convert the file using puttygen as suggested by bwight.
In addition to the other answers, the issue might come from the fact you haven't specified which user you want to connect as.
For example ssh -i francky.pem 208.52.170.43 will ask you for your password on Mac, whereas ssh -i francky.pem root#208.52.170.43 shouldn't. Note that on Linux you don't specify the user.
I was running into the exact same problem in MAC, I found a quite simple way of getting rid of it.
Instead of using ssh -i IP address, use the following>
ssh user#IP
Hope you already found the answer after this long time :)
In my case, the problem was the file's break type. Try this:
1.- Open the .pem file with TextWrangler
2.- At Bottom of app, verify if the Break Type is "Windows(CRLF)".
This issue had me pulling my hair out for 20 min or so. Realized that I was able to connect successfully from another terminal window. In my case I just had to close out the current terminal window and use another or new window. Very strange, but may help you out.

How to use ssh keys for sshfs automount from mac to ubuntu

I want to be able to automount an ubuntu volume on my mac using sshfs. I tried using ssh key-gen and copying the id_rsa file, adding the pub key to my authorized keys, using all sorts of sshfs -o options, to no avail.
The procedure for setting up ssh key authentication is the same whether you are using it for sshfs or something else.
On the client side you generate a key. In this case we are making a DSA key
ssh-keygen -t dsa
You should now have an id_dsa file and an id_dsa.pub file in your .ssh directory. The pub file is your public key, and its contents get placed inside the authorized_keys file (or authorized_keys2 if you are using a DSA key as above) in the .ssh directory of the server to which you want to log in.
If you are on a Linux client, you can probably push the key to the server using the ssh-copy-id command.
ssh-copy-id user#server:
On the client side the id_dsa file needs to be owned by you and have 600 permissions, which is the default when you generate the key. On the server side the authorized_keys file needs to be owned by you and not be world writable, which should be the case if you don't do anything weird when copying it over like doing that as root.

Resources