I am trying to ssh into my ec2 instance from a centos 7 machine. I have added .pem file to .ssh folder.
Am i missing something?
[root#localhost .ssh]# cd /home/###/.ssh/
[root#localhost .ssh]# ls
##.pem
root#localhost .ssh]# ssh centos#10.100.140.52 -vvv
debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
I see you are using a root shell, but your question states the key credentials are stored in a user's home directory. Does this work as that user, i.e.,
[root#localhost .ssh]# su - ###
[####localhost ~]$ ssh centos#10.100.140.52 -vvv
You can also try to override where the ssh client is looking for .ssh files, although ssh gets picky about mismatched file permissions, i.e.,
[root#localhost ~]# ssh -i ~###/.ssh/something.pem centos#10.100.140.52 -vvv
You can store connection "profiles" in ~/.ssh/config, i.e.,
Host ec2
HostName 10.100.140.52
IdentityFile ~/.ssh/identity_file
You're the root user - it doesn't matter if you've got a pem file in the same directory, it's going to look in the default directory (/root/.ssh in your case). If you want to use that pem file, use the "-i" command line option:
ssh -i something.pem centos#10.100.140.52 -vvv
This is my first time accessing GitHub and I'm not experienced using a console. I am on a MacBook using Bash. When I try to access GitHub, I get this:
git clone git#github.com:dhulihan/league-of-legends-data-scraper.git
Cloning into 'league-of-legends-data-scraper'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I've tried following the instructions on Github page about permission being denied.
When I use ssh -vT git#github.com, I get the following:
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.252.129] port 22.
debug1: Connection established.
debug1: identity file /Users/XXXX/.ssh/id_rsa type -1
debug1: identity file /Users/XXXX/.ssh/id_rsa-cert type -1
debug1: identity file /Users/XXXX/.ssh/id_dsa type -1
debug1: identity file /Users/XXXX/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/XXXX/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/XXXX/.ssh/id_rsa
debug1: Trying private key: /Users/XXXX/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
Next, eval "$(ssh-agent -s)" returns "Agent pid 2314",
however ssh-add -l returns "The agent has no identities."
And that is where I am stuck.
Full details in this answer.
In summary, when ssh-add -l returns “The agent has no identities”, it means that keys used by ssh (stored in files such as ~/.ssh/id_rsa, ~/.ssh/id_dsa, etc.) are either missing, they are not known to ssh-agent, which is the authentication agent, or that their permissions are set incorrectly (for example, world writable).
If your keys are missing or if you have not generated any, use ssh-keygen -t rsa, then ssh-add to add them.
If keys exist but are not known to ssh-agent (like if they are in a non-standard folder), use ssh-add /path/to/my-non-standard-ssh-folder/id_rsa to add them.
See this answer if you are having trouble with ssh-add or ssh-agent.
try this:
ssh-add ~/.ssh/id_rsa
worked for me
THE 2019 ANSWER for macOS Sierra & High Sierra & Catalina:
PS: most of the other answers will have you to create a new ssh key ... but you don't need to do that :)
As described in detail on https://openradar.appspot.com/27348363, macOS/OS X till Yosemite used to remember SSH keys added by command ssh-add -K <key>
So here are the 4 steps i had to take in order for it to work:
1: ssh-add ~/.ssh/PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
2: Add the following in ~/.ssh/config
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)
3: make sure to remove any gitconfig entry that use osxkeychain helper:
https://github.com/gregory/dotfiles/commit/e38000527fb1a82b577f2dcf685aeefd3b78a609#diff-6cb0f77b38346e0fed47293bdc6430c6L48
4: restart your terminal for it to take effect.
I have been stucked a while on the same problem, which I eventually resolved.
My problem: I could not execute any push. I could check & see my remote (using git remote -v), but when I executed git push origin master, it returned : Permission denied (publickey). fatal: Could not read from remote repository. and so.
How I solved it :
I generated a key using ssh-keygen -t rsa. Entering a name for the key file (when asked) was useless.
I could then add the key (to git): ssh-add /Users/federico/.ssh/id_rsa , which successfully returned Identity added: /Users/myname/.ssh/id_rsa (/Users/myname/.ssh/id_rsa)
I added the SSH key to github using this help page.
Having tried all the commands in Github's 'Permission denied publickey' help page, only the ssh-add -l command worked / seemed useful (after having ran the previous steps), it successfully returned my key. The last step shows you where to check your public key on your GitHub page. And this command will help you check all your keys : ls -al ~/.ssh.
Then the push command eventually worked !
I hope this will help !
Best luck to all.
Run the following commands:
ssh-keygen -t rsa
ssh-add /Users/*yourUserNameHere*/.ssh/id_rsa**
pbcopy < ~/.ssh/id_rsa.pub**
Go to your Github account : https://github.com/settings/profile
1) Click : SSH and GPG keys
2) New SSH Key and Past it there
3) Add SSH Key
Done!
tl;dr
ssh-add # no parameter
# Identity added: /home/<user>/.ssh/id_rsa (user#host)
Further readings
two files necessary in the ssh - user - folder:
ls ~/.ssh
id_rsa id_rsa.pub
If the files are not there, enter command ssh-keygen
Now start the ssh-agent:
eval `ssh-agent -s`
Verify
ssh-add -l
# voila:
2048 SHA256:<key one> user#host (RSA)
Bonus
check the local SHA256 from above with the Github SHA256 from your user settings -> SSH Keys. If they are equal you should be able to push/pull to/from Github using your keys.
first of all you need to go in your ssh directory
for this type following command in your terminal in mac or whatever you use in window
cd ~/.ssh
now it is in the ssh
here you can find all you ssh key/files related to your all projects. now, type the following command to show you if any ssh key available
ls
this will show you all available ssh, in my case there were two
now, you will need to start an agent to add a ssh in it. For this type following command
eval "$(ssh-agent -s)"
now last but not least you will add a ssh in this agent type following command
ssh-add ~/.ssh/your-ssh
replace
replace your-ssh with your ssh file name which you got a list form second step ls command
This could cause for any new terminal, the agent id is different.
You need to add the Private key for the agent
$ ssh-add <path to your private key>
This worked for me:
chmod 700 .ssh
chmod 600 .ssh/id_rsa
chmod 644 .ssh/id_rsa.pub
Then, type this:
ssh-add ~/.ssh/id_rsa
For my mac Big Sur, with gist from answers above, following steps work for me.
$ ssh-keygen -q -t rsa -N 'password' -f ~/.ssh/id_rsa
$ ssh-add ~/.ssh/id_rsa
And added ssh public key to git hub by following instruction;
https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account
If all gone well,
you should be able to get the following result;
$ ssh -T git#github.com
Hi user_name! You've successfully authenticated,...
One additional element that I realized is that typically .ssh folder is created in your root folder in Mac OS X /Users/. If you try to use ssh -vT git#github.com from another folder it will give you an error even if you had added the correct key.
You need to add the key again (ssh-add 'correct path to id_rsa') from the current folder to authenticate successfully (assuming that you have already uploaded the key to your profile in Git)
I had this issue after restoring a hard drive from a backup.
My problem:
I could check & see my remote (using git remote -v), but when I executed git push origin master, it returned : Permission denied (publickey). fatal: Could not read from remote repository.
I already had an SSH folder and SSH keys, and adding them via Terminal (ssh-add /path/to/my-ssh-folder/id_rsa) successfully added my identity, but I still couldn't push and still got the same error. Generating a new key was a bad idea for me, because it was tied to other very secure permissions on AWS.
It turned out the link between the key and my Github profile had broken.
Solution:
Re-adding the key to Github in Profile > Settings > SSH and GPG keys resolved the issue.
Also:
My account had 2-factor authentication set up. When this is the case, if Terminal requests credentials, use your username - but NOT your Github password. For 2-factor authentication, you need to use your authentication code (for me, this was generated by Authy on my phone, and I had to copy it into Terminal for the pw).
If you are using Linux or Windows open terminal or cmd in directory you want your keys in. Create a pair of private-public key
$ ssh-keygen -t ed25519 -C "your_email#example.com"
If you are using a legacy system that doesn't support the Ed25519 algorithm, use:
$ ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
Generating public/private ALGORITHM key pair.
Enter a file in which to save the key (/c/Users/YOU/.ssh/id_ALGORITHM):[Press enter any name you like your private public keys file to be]
Enter passphrase (empty for no passphrase): [Type a passphrase or enter for without it]
Enter same passphrase again: [Type a passphrase or enter for without it]
Now, in Linux
$ sudo cp <filename without .pub ending> ~/.ssh
In Windows simply copy the <filename without .pub ending> file in this C:\Users\your_username\.ssh directory
And then
$ ssh-add ~/.ssh/<filename without .pub ending>
It may work now!
After struggling for long I was finally able to resolve this issue on Windows, For me the User env variable GIT_SSH was set to point to
"C:\Program Files(x86)\WinScp\PuTTY\plink.exe"
which was installed along with WinScp. I changed the pointing to use default ssh.exe which comes with git-scm "C:\Program Files\Git\usr\bin\ssh.exe"
Steps for BitBucket:
if you dont want to generate new key, SKIP ssh-keygen
ssh-keygen -t rsa
Copy the public key to clipboard:
clip < ~/.ssh/id_rsa.pub
Login to Bit Bucket:
Go to View Profile -> Settings -> SSH Keys (In Security tab)
Click Add Key,
Paste the key in the box, add a descriptive title
Go back to Git Bash :
ssh-add -l
You should get :
2048 SHA256:5zabdekjjjaalajafjLIa3Gl/k832A /c/Users/username/.ssh/id_rsa (RSA)
Now: git pull should work
This worked for me also:
chmod 700 .ssh
chmod 600 .ssh/id_rsa
chmod 644 .ssh/id_rsa.pub
Then, type this: ssh-add ~/.ssh/id_rsa
Sometimes it could be useful to check ~/.ssh/config
it should look like this
Host github.com
IdentityFile ~/.ssh/id_rsa
id_rsa can be different if you linked a different key.
I'm trying to copy a file from an ec2 instance to my local machine. Here's the command:
scp -v -i commoncrawl_practice.pem ec2-user#ec2-54-86-8-91.compute-1.amazonaws.com:/home/ec2-user/testfile .
And here's where it hangs:
debug1: Trying private key: commoncrawl_practice.pem
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to ec2-54-86-8-91.compute-1.amazonaws.com ([54.86.8.91]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions#openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: scp -v -f /home/ec2-user/testfile
Thanks in advance.
Check if you have a ~/.bashrc file on the destination which prints stuff to your terminal. If yes, disable it for non-interactive shells by inserting
[[ $- == *i* ]] || return
before printing anything.
(solution found on https://unix.stackexchange.com/questions/18231/scp-fails-without-error)
Try SFTP as an alternative to SCP.
Following this post to fix the following error:
>> ssh -vT git#github.com
OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /Users/user/.ssh/config
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [207.97.227.239] port 22.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/id_rsa type 1
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/user/.ssh/id_dsa type -1
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5github2
debug1: match: OpenSSH_5.1p1 Debian-5github2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /Users/user/.ssh/known_hosts:10
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/user/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
Through the post made sure that I have a key and SSH is using it. I have even verified that the public key is attached to my github account. Not sure of the -1 in the last 3 lines? Saw all the related posts but no help.
debug1: identity file /Users/user/.ssh/id_rsa type 1
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: identity file /Users/user/.ssh/id_dsa type -1
debug1: identity file /Users/user/.ssh/id_dsa-cert type -1
I was doing ssh -T git#github.com. I had to do ssh -T git#github.company's-github-account-name.com. All set now.
The most likely problem, it seems, is that the public key isn't actually correctly attached to your github account. Can you confirm that the output of
ssh-keygen -y -f /Users/user/.ssh/id_rsa
is exactly the same as what you put in Github, and that if you do
ssh-keygen -y -f /Users/user/.ssh/id_rsa > tmp
ssh-keygen -l -f tmp
..that the fingerprint shown matches exactly one of the fingerprints shown at https://github.com/settings/ssh ?
Edit: you confirmed. It looks like you've done everything right, then. I can't think of much more that could be going wrong. I suppose you might be getting the wrong remote host (the IP is right, but a malicious person or a misbehaving corporate firewall could still be sending the packets to the wrong place). You can check this by seeing what fingerprint you've stored in your known_hosts file:
ssh-keygen -F github.com > tmp
ssh-keygen -l -f tmp
The output should start with:
2048 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
If it does, then I suppose it might be a problem on the github side after all. Maybe they have some sort of delay in between receiving your public key and propagating it to the main ssh server. You probably ought to try the "contact a human" link at the bottom of the page you cited.
Extensive troubleshooting of this GIT issue “Git – Permission denied (publickey)” can be done with the below command:
ssh -vT git#github.com
Navigate to .ssh directory inside your home directory
cd ~/.ssh
Generate the public/private rsa key pair
ssh-keygen
Copy the SSH key to the clipboard using the below command
cat id_rsa.pub | clip
Navigate to your GIT repository in https://github.com/
Go to Account Settings –> SSH Keys
Click on Add SSH key and store the key
I agree with the answer posted by #Ava. Using ssh -T git#github."company's_github_account".com It worked for me. Many times, we do not realize that a simple fix exists for seemingly complex problems.
I am able to use ssh (i.e., for 'git' with heroku or github etc.) through GitBash, but I cannot do the same from Windows cmd prompt on the same machine. What can be the problem? If I recall correctly, it used to work from cmd prompt.
The error I'm getting is:
Permission denied (publickey). fatal: The remote end hung up unexpectedly
I got both logs: here is last four lines from cmd which are different from 'git bash':
debug1: Trying private key: /.ssh/identity
debug1: Trying private key: /.ssh/id_rsa
debug1: Trying private key: /.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
in case of Git bash: the respective lines are:
debug1: Trying private key: /c/Users/user1/.ssh/identity
debug1: Offering public key: /c/Users/user1/.ssh/id_rsa
debug1: Remote: Forced command: gerve user1
debug1: Remote: Port forwarding disabled.
debug1: Remote: X11 forwarding disabled.
Resolved
As hinted by #snemarch, setting following env var solved my problem:
set HOME=C:\Users\user1
Since you are using GitHub, from cmd try
ssh -v -T git#github.com
See the keys that it is presenting. Maybe try from Git Bash also and compare the output.
This could be because %HOME% is not correctly set. Set it to the directory that contains your .ssh directory ( and hence the keys)
Look at the file paths - "/.ssh/identity", in the case of cmd.exe, is probably not where you've got your SSH keys :). Probably a case of homedir expansion being done when you're on the git-bash, but not on native cmd.exe .
Instead of using cygwin ssh and the regular ssh key files, consider using PuTTY's plink for SSH program and pageant for ssh-agent.
I'd double check your system path includes a reference to your git/bin location