Skip to content

Commit 1d6a7ba

Browse files
committed
Add ssh-copy-id, close raspberrypi#771
1 parent 21814ca commit 1d6a7ba

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

remote-access/ssh/passwordless.md

+24-17
Original file line numberDiff line numberDiff line change
@@ -6,73 +6,80 @@ It is possible to configure your Pi to allow your computer to access it without
66

77
First, check whether there are already keys on the computer you are using to connect to the Raspberry Pi:
88

9-
```
9+
```bash
1010
ls ~/.ssh
1111
```
1212

1313
If you see files named `id_rsa.pub` or `id_dsa.pub` you have keys set up already, so you can skip the generating keys step (or delete these files with `rm id*` and make new keys).
1414

1515
## Generate new SSH keys
1616

17-
To generate new SSH keys enter the following command (Choose a sensible hostname such as `<YOURNAME>@<YOURDEVICE>` where we have used `eben@pi`):
17+
To generate new SSH keys enter the following command:
1818

19-
```
20-
ssh-keygen -t rsa -C eben@pi
19+
```bash
20+
ssh-keygen
2121
```
2222

23-
You can also use a more descriptive comment using quotes if you have spaces, e.g. `ssh-keygen -t rsa -C "Raspberry Pi #123"`
24-
2523
Upon entering this command, you'll be asked where to save the key. We suggest you save it in the default location (`/home/pi/.ssh/id_rsa`) by just hitting `Enter`.
2624

2725
You'll also be asked to enter a passphrase. This is extra security which will make the key unusable without your passphrase, so if someone else copied your key, they could not impersonate you to gain access. If you choose to use a passphrase, type it here and press `Enter`, then type it again when prompted. Leave the field empty for no passphrase.
2826

29-
Now you should see the files `id_rsa` and `id_rsa.pub` in your `.ssh` directory in your home folder:
27+
Now look inside your `.ssh` directory:
3028

31-
```
29+
```bash
3230
ls ~/.ssh
3331
```
3432

33+
and you should see the files `id_rsa` and `id_rsa.pub`:
34+
3535
```
3636
authorized_keys id_rsa id_rsa.pub known_hosts
3737
```
3838

3939
The `id_rsa` file is your private key. Keep this on your computer.
4040

41-
The `id_rsa.pub` file is your public key. This is what you put on machines you want to connect to. When the machine you try to connect to matches up your public and private key, it will allow you to connect.
41+
The `id_rsa.pub` file is your public key. This is what you share with machines you want to connect to. When the machine you try to connect to matches up your public and private key, it will allow you to connect.
4242

4343
Take a look at your public key to see what it looks like:
4444

45-
```
45+
```bash
4646
cat ~/.ssh/id_rsa.pub
4747
```
4848

4949
It should be in the form:
5050

51-
```
52-
ssh-rsa <REALLY LONG STRING OF RANDOM CHARACTERS> eben@pi
51+
```bash
52+
ssh-rsa <REALLY LONG STRING OF RANDOM CHARACTERS> user@host
5353
```
5454

5555
## Copy your public key to your Raspberry Pi
5656

5757
If your Pi does not have an .ssh directory you will need to set one up so that you can copy the key from your computer.
5858

59-
```
59+
```bash
6060
cd ~
6161
install -d -m 700 ~/.ssh
6262
```
6363

6464
To copy your public key to your Raspberry Pi, use the following command to append the public key to your `authorized_keys` file on the Pi, sending it over SSH:
6565

66+
```bash
67+
ssh-copy-id <USERNAME>@<IP-ADDRESS>
6668
```
69+
70+
*Note that this time you will have to authenticate with your password.*
71+
72+
Alternatively, if the `ssh-copy-id` is not available on your system, you can copy the file manually over SSH:
73+
74+
```bash
6775
cat ~/.ssh/id_rsa.pub | ssh <USERNAME>@<IP-ADDRESS> 'cat >> .ssh/authorized_keys'
6876
```
6977

70-
Note that this time you will have to authenticate with your password.
71-
7278
Now try `ssh <USER>@<IP-ADDRESS>` and you should connect without a password prompt.
7379

74-
If you see a message "Agent admitted failure to sign using the key" then add your RSA or DSA identities to the authentication agent `ssh-agent` then execute the following command:
75-
```
80+
If you see a message "Agent admitted failure to sign using the key" then add your RSA or DSA identities to the authentication agent `ssh-agent` then execute the following command:
81+
82+
```bash
7683
ssh-add
7784
```
7885

0 commit comments

Comments
 (0)