Page cover image

Raspberry Pi Commands

Basic Commands

Finding available devices

arp -a

This command lists all devices connected to the same network as your Raspberry Pi. It helps you identify the IP addresses and MAC addresses of the devices.

Connecting to the Raspberry Pi via SSH using the device name:

ssh pi@raspberrypi

This command establishes an SSH connection to your Raspberry Pi using its device name. By default, the username is "pi" and the device name is "raspberrypi".

Connecting to the Raspberry Pi via SSH using the IP address:

This command establishes an SSH connection to your Raspberry Pi using its IP address. Replace "192.168.64.xxx" with the actual IP address of your Raspberry Pi.

User Management

Adding a new user with a home directory

sudo useradd -m sven -G sudo

This command creates a new user named "sven" and assigns them to the "sudo" group, granting them administrative privileges. The "-m" flag creates a home directory for the user. User information is stored in the "/etc/passwd" file.

Setting a password for a user

sudo passwd sven

This command sets a password for the user "sven". The password is stored in an encrypted format in the "/etc/shadow" file.

System Information

Getting system information (e.g., IP address):

ifconfig

This command displays information about the network interfaces, including the IP address assigned to each interface.

Getting network information

iwconfig

This command provides information about the wireless network interfaces, including the connected Wi-Fi network and signal strength.

Getting the hostname

hostname

This command displays the hostname of your Raspberry Pi.

Getting the IP address associated with the hostname:

hostname -I

This command shows the IP address assigned to the hostname of your Raspberry Pi.

Checking for all connected USB devices

lsusb

This command lists all the USB devices currently connected to your Raspberry Pi.

System Configuration

Accessing the Raspberry Pi configuration tool:

sudo raspi-config

This command opens the Raspberry Pi configuration tool, which allows you to modify various system settings, such as enabling SSH, changing the password, and configuring the locale.

Starting the graphical user interface (GUI):

startx

This command starts the graphical user interface on your Raspberry Pi, if one is installed.

Rebooting the system

sudo reboot

This command reboots your Raspberry Pi.

Shutting down the system

sudo shutdown -h now

This command shuts down your Raspberry Pi immediately.

Web Server Setup

Updating the system

sudo apt-get update && sudo apt-get upgrade

This command updates the package list and upgrades the installed packages to their latest versions.

Installing the Apache web server and PHP:

sudo apt-get install apache2 php5

This command installs the Apache web server and PHP on your Raspberry Pi. It allows you to host web pages and run PHP scripts.

Installing MySQL

sudo apt-get install mysql-server mysql-client php5-mysql

This command installs the MySQL database server, client, and the necessary PHP extension for interacting with MySQL databases.

Restarting the Apache web server

sudo service apache2 restart

This command restarts the Apache web server to apply any configuration changes.

Audio Playback

Playing an audio file

omxplayer audio.mp3

This command plays an audio file named "audio.mp3" using the omxplayer, which is a command-line media player for the Raspberry Pi.

  1. Adjusting the volume:

    • Press + to increase the volume.

    • Press - to decrease the volume.

Remote Control

Installing XRDP for remote desktop access

sudo apt-get install xrdp

This command installs the XRDP server, which allows you to access your Raspberry Pi's desktop environment remotely using the Remote Desktop Protocol (RDP).

Installing VNC server for remote access

sudo apt-get install tightvncserver

This command installs the VNC server, which enables remote access to your Raspberry Pi's desktop environment.

Starting the VNC server

tightvncserver

This command starts the VNC server on your Raspberry Pi.

  • The Ethernet port for VNC is 5900.

  • The WLAN (Wi-Fi) port for VNC is 5901.

File Sharing

Installing file sharing support

sudo apt-get install netatalk

This command installs the Netatalk package, which provides file sharing capabilities using the Apple Filing Protocol (AFP).

Connecting to the Raspberry Pi's file share from macOS:

  • Open the "Connect to Server" dialog using the shortcut ⌘K.

  • Enter the following address: afp://192.168.64.xxx, replacing "192.168.64.xxx" with the actual IP address of your Raspberry Pi.

These are just a few examples of the many commands and configurations available on the Raspberry Pi.

The Raspberry Pi offers a wide range of possibilities, and exploring the official documentation and community resources can help you discover more commands and features specific to your needs.

Remember to use commands with caution, especially those that require sudo privileges, as they can have significant impact on your system.

It's always a good practice to understand the purpose and potential consequences of a command before executing it.

Last updated

Was this helpful?