Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Create a ssh key:

$ ssh-keygen -t rsa –P ""

Moving the key to authorized key:

$ cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys

bash: /home/user/.ssh/authorized_keys: No such file or directory
share|improve this question
    
Same question, why you need to add the key to your own host? –  Braiam May 16 at 1:28
    
@Braiam I've done this when my home directory was on network drive. This allowed me to ssh to any machine that mounted this drive. So I wasn't sshing to my own host. –  FDinoff May 16 at 2:20

3 Answers 3

bash: /home/user/.ssh/authorized_keys: No such file or directory

An element of the path /home/user/.ssh/ does not exist; the shell (bash) checks the redirection (>>) before it executes the command (cat). If /home/user does exist and you try this:

cat $HOME/.ssh/id_rsa.pub >> $HOME/test_this

You'll now get:

cat: /home/user/.ssh/id_rsa.pub: No such file or directory

Since that file can't be in that place, if /home/user/.ssh/ did not exist to start with.

You're following some instructions having possibly skipped some bits. To create the directory:

mkdir $HOME/.ssh
chmod 700 $HOME/.ssh

However, id_rsa.pub won't be there. It will be wherever you ran the ssh-keygen command in the first place.

share|improve this answer

Make sure that you are logged in as the user that you want to create the ssh key for first (or be prepared to modify the paths in the command to the correct home directory).

Then just create the directory:

mkdir ~/.ssh

Create the file using the cat command you have listed above. Then don't forget to set the permissions correctly:

chmod 400 ~/.ssh/authorized_keys

You might want to make sure that the .ssh directory has appropriate permissions as well.

share|improve this answer

If possible I always encourage people to use the commandline tool ssh-copy-id.

$ ssh-copy-id -h
Usage: /usr/bin/ssh-copy-id [-i [identity_file]] [user@]machine

If you just want to copy your default SSH public key to a remote sever you simply run the following command:

$ ssh-copy-id user@remoteserver

I show an actual full example of how to use this tool in this Q&A titled: Can't share an ssh connection with rsync.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.