Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

ssh-add problems with SSH agent and related

Hi,

Some time ago we have posted about resolving git errors related to permissions denied for the ssh keys: http://devmain.blogspot.co.uk/2014/09/git-error-permission-denied-publickey.html

The solution was to try running the following command:
ssh-add

However what if running it results in the following error:
"Could not open a connection to your authentication agent"

Well there is a solution to that one too :)

It may mean that the SSH agent is not running and you can try to start it prior to running the command. If you run GIT bash on Windows you can try the following command:
eval `ssh-agent -s`

or if that's not the case you can try directly start ssh-agent

After that just try again with ssh-add.

Hope that helps someone.

Cheers!

Git Error: Permission denied (publickey)

Hello,

The other day I was trying to fetch the changes from the remote repo and the following error has been displayed:

$ git fetch origin

Agent admitted failure to sign using the key.
# Permission denied (publickey).



In this case the reason was that I've changed / switched between two different ssh keys. However if you got similar issues the problem has been fixed by telling ssh to use the key by running the following command:

$ ssh-add

That's it - problem solved :)


Secure copying via SCP

SCP allows to securely transfer files between a local host and a remote host or between two remote hosts. It is based on the SSH protocol.

Copying file to host:
scp file user@host:directory/

Copying file from host to current directory:
scp user@host:directory/file .

To copy entire folders use -r parameter:
scp -r user@host:directory/folder .

SCP by default uses port 22. Sometimes remote host may have it blocked or just uses other port. You can specify the different port using -P parameter.

To copy all files from remote host using port 23: 
scp -P 23 user@host:/directory/* .

To copy all files from current directory to remote host using port 23:
scp -P 23 * user@host:/directory

How to set up SSH keys

To use SSH you will need the keys. To generate them run the command:

ssh-keygen

It will prompt you for a password or just press <ENTER> to use an empty one.

Two keys have been generated under hidden directory /home/your_username/.ssh
  • id_rsa (private)
  • id_rsa.pub (public)

The last and very important step is to restric access to your keys for the others. Run the commands:

chmod 600 id_rsa
chmod 600 id_rsa.pub

That's all for initial setup. Done!

To log in using your keys use the command:
ssh username@address

If you want to bind some address/port use the command:
ssh -L port:host:hostport username@address

for example: ssh -L 8888:localhost:8888 username@address