1

My co-worker sent me a '.ssh' directory with files in it. He said that I can put that directory in my user directory then connect to ssh without password (ssh root@ip).

I put that directory in my home directory then tried ssh root@ip, but it didn't work.

Am I missing something?

2
  • Please post the output of ls -l ~/.ssh. May 9, 2011 at 2:27
  • 7
    I have no words to express how horrible this is. Enumerating: 1. sending a .ssh directory around (which contains private keys); 2. that, to connect without a password, which means that you have unprotected keys, password-less keys, instead of using an ssh-agent; 3. that, for the root account. Please, learn how to properly use SSH.
    – Juliano
    May 9, 2011 at 2:41

3 Answers 3

5

Two things here.

1) You coworker sent you a .ssh directory (horrible idea btw, but thats another issue..) Inside here there is a file called authorized_keys which holds one or many "SSH Public keys". The "connection without passphrase" that he is talking about happens when you connect and offer up a private key and the system recognizes a matching public key in .ssh/authorized_keys. If you do not have said ssh private key then this folder is essentially useless. This key needs to be on the client side not server side. Look inside the .ssh folder, is there a id_rsa file? if so copy that to your client and load it up inside Pagent or inside Putty.

2) You said you put this inside your home directory, lets say /home/Moon. Now you try to login as root@ip.

SSH will look inside /root/.ssh/ for the files NOT /home/moon/.ssh/ because you tried to login as root NOT as Moon. Depending on your distro you can log into your own account and sudo or su to root. Putting a passphrase-less key for root is all kinds of horrible.

Finally a word of warning.. you coworker gave you his .ssh directory that contains an authorized_keys file to some unknown private key. Unless you really really really trust your coworker this is a horrible idea. If your home folder has a .ssh directory with someone elses public key in the authorized_keys file then they can log into your user WITHOUT providing your system password. Essentially your coworker could log in as you and do whatever he wanted under your name and no one could prove otherwise.

If you want to do this yourself and do it properly do the following.

  1. Logged in as your normal user type in the command

    ssh-keygen -t rsa

  2. Follow the prompts, select default for everything (I recommend you enter a password for your key however).

  3. Copy your public key into your authorized keys file, deleting old content.

    cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys

  4. Copy the ~/.ssh/id_rsa file to your client computer, using either Pagent, Putty, ssh -i, or some other key manager load/open id_rsa. Now SSH to yourusername@ip and you will not need a prompt.

0

The .ssh directory should (If your co-worker has done it correctly) contain a public key which you need to add to your authorized keys file. Open a terminal and type
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
(That may not be the correct command, the directory you were sent should have one .pub file in, cat that instead, whatever it's called)
You should probably also suggest to them that sending the entire SSH directory is a very bad idea, for one thing you now have his private key. Also any previously authorized keys or known hosts have been overwritten, they should have just sent you the id_rsa.pub file.
Alternatively your sshd may not be configured to allow key based auth, consult the docs for specific instructions on how to do this.

0

Another possibility: depending on how you extracted the .ssh directory, you may not own the files you created (which is a prerequisite for most versions of ssh to connect). Try chown -R $USER. ~/.ssh and chmod -R g-rwx,o-rwx ~/.ssh.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .