You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: remote-access/ssh/passwordless.md
+24-17
Original file line number
Diff line number
Diff line change
@@ -6,73 +6,80 @@ It is possible to configure your Pi to allow your computer to access it without
6
6
7
7
First, check whether there are already keys on the computer you are using to connect to the Raspberry Pi:
8
8
9
-
```
9
+
```bash
10
10
ls ~/.ssh
11
11
```
12
12
13
13
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).
14
14
15
15
## Generate new SSH keys
16
16
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:
18
18
19
-
```
20
-
ssh-keygen -t rsa -C eben@pi
19
+
```bash
20
+
ssh-keygen
21
21
```
22
22
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
-
25
23
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`.
26
24
27
25
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.
28
26
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:
30
28
31
-
```
29
+
```bash
32
30
ls ~/.ssh
33
31
```
34
32
33
+
and you should see the files `id_rsa` and `id_rsa.pub`:
34
+
35
35
```
36
36
authorized_keys id_rsa id_rsa.pub known_hosts
37
37
```
38
38
39
39
The `id_rsa` file is your private key. Keep this on your computer.
40
40
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.
42
42
43
43
Take a look at your public key to see what it looks like:
44
44
45
-
```
45
+
```bash
46
46
cat ~/.ssh/id_rsa.pub
47
47
```
48
48
49
49
It should be in the form:
50
50
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
53
53
```
54
54
55
55
## Copy your public key to your Raspberry Pi
56
56
57
57
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.
58
58
59
-
```
59
+
```bash
60
60
cd~
61
61
install -d -m 700 ~/.ssh
62
62
```
63
63
64
64
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:
65
65
66
+
```bash
67
+
ssh-copy-id <USERNAME>@<IP-ADDRESS>
66
68
```
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:
Note that this time you will have to authenticate with your password.
71
-
72
78
Now try `ssh <USER>@<IP-ADDRESS>` and you should connect without a password prompt.
73
79
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:
0 commit comments