# Accessing the Device

Remote or local access to the device is needed to program it with either Python or C++.

## SSH

Factory credentials:

| | |
|---|---|
| Username | `slm-rp4` |
| Password | `slm-rp4` |
| Hostname | `slm-rp4` |

```bash
ssh slm-rp4@<device-ip>
```

If the network resolves the hostname:

```bash
ssh slm-rp4@slm-rp4
```

Change the default password on every unit before deployment. See [Raspberry Pi / Device Setup](../hardware/raspberry-pi-setup.md).

### Development over SSH

Editing files directly on the device with `nano` or `vim` is possible. For a full IDE experience, Visual Studio Code with the **Remote - SSH** extension opens a folder on the SLM-RP4 as if it were local and supports editing, running, and debugging without copying files back and forth.

### Key-based authentication

Key-based authentication is more secure than a password and avoids repeated prompts. From the workstation:

```bash
# Generate a key if one does not already exist
ssh-keygen -t ed25519

# Copy the public key to the device
ssh-copy-id slm-rp4@<device-ip>
```

Shorten the command with a host entry in `~/.ssh/config`:

```text
Host rp4
  HostName 192.168.1.50
  User slm-rp4
```

```bash
ssh rp4
```

Once keys work, disable password authentication in `/etc/ssh/sshd_config`:

```text
PasswordAuthentication no
```

### Copying files

```bash
# To the device
scp myprogram.py rp4:~/

# From the device
scp rp4:~/logs/output.csv .

# A whole directory, kept in sync
rsync -av ./myproject/ rp4:~/myproject/
```

## Local display

Connect a monitor to a micro-HDMI port and a USB keyboard. The device boots to a desktop environment.

System settings that `raspi-config` handles from the shell are also available graphically, under **Preferences → Raspberry Pi Configuration**:

```{image} ../../images/hardware/raspi-config.png
:alt: The Raspberry Pi Configuration entry in the desktop Preferences menu
:width: 450px
:align: center
```

A local display is the fallback that always works. If a static IP has been configured incorrectly, the network interface disabled, or the password lost, this is how to regain access.

## VNC

A VNC server runs by default and listens on port 5900. Connect from the workstation with any VNC client, using the device's IP address.

If VNC has been disabled on the unit, re-enable it from a terminal:

```bash
sudo raspi-config
```

Navigate to **Interface Options → VNC** and enable it.

```{admonition} Secure the VNC service
:class: warning

VNC provides full desktop control of a device that operates machinery. Set a strong VNC password and keep the port on the control network rather than exposing it more widely. Disable the service if it is not used.
```
