> For the complete documentation index, see [llms.txt](https://notes.lcsrg.me/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.lcsrg.me/home-setup/raspberry/untitled.md).

# SSH configuration

## Set static IP

#### See what's managing eth0

Run

```
systemctl is-active NetworkManager
systemctl is-active systemd-networkd
nmcli dev status 2>/dev/null || true
```

#### If NetworkManager is active

1. Get the connection name for eth0:

```
nmcli -g NAME,DEVICE con show --active
```

2. Set static IP (replace CONN\_NAME with the name you got):

```
sudo nmcli con mod "CONN_NAME" ipv4.addresses 192.168.1.101/24
sudo nmcli con mod "CONN_NAME" ipv4.gateway 192.168.1.1
sudo nmcli con mod "CONN_NAME" ipv4.dns "192.168.1.1 1.1.1.1"
sudo nmcli con mod "CONN_NAME" ipv4.method manual
sudo nmcli con down "CONN_NAME" && sudo nmcli con up "CONN_NAME"
```

3. Verify

```
ip -4 addr show dev eth0
ip route | grep default
```

You want:

* inet 192.168.1.101/24
* default via 192.168.1.1 dev eth0 (may or may not still say proto dhcp, but the key is the src becomes .101 and the address is static)

#### If systemd-networkd is active

Open the file `/etc/dhcpcd.conf` and place the following lines of code, which configures the connection using the `eth0` (ethernet) interface:

{% code title="/etc/dhcpcd.conf" %}

```
# Example static IP configuration:
interface eth0
static ip_address=192.168.1.X/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4
```

{% endcode %}

In the example above, we have used `192.168.1.X/24` as the static private IP and `192.168.1.1` is the IP of our router (a.k.a. gateway, check it using `router -n` command).

Finally, restart the device

```
sudo reboot
```

{% hint style="info" %}

* [How to Setup a Raspberry Pi Static IP Address](https://pimylifeup.com/raspberry-pi-static-ip-address/) (Post)
* [How to assign static IP address to Raspberry Pi](https://www.youtube.com/watch?v=LCJtUbRlIXE) (Video)
  {% endhint %}

## Change ssh port

A good practice to increase security is to change the default ssh port (22) to a different one (higher than 1000, lower than 65535). Open the ssh configuration (file /etc/ssh/sshd\_config) and uncomment the line called “Port 22” and change it to&#x20;

{% code title="/etc/ssh/sshd\_config" %}

```
Port [SSH_NEW_PORT]
```

{% endcode %}

Finally, restart ssh service

```
sudo service ssh restart
```

Now, to access the raspberry type:

```
$ ssh -p [SSH_NEW_PORT] pi@192.168.1.X
```

{% hint style="info" %}
[How to change your SSH Port on the Raspberry Pi](http://kamilslab.com/2016/12/10/how-to-change-your-ssh-port-on-the-raspberry-pi/)
{% endhint %}
