Follow by Email

Blog Archive

Search This Blog

Setup the Raspberry Pi as a server step by step

Set up the Raspberry Pi as a server step by step how to setup raspberry pi as a 24/7 server
Share it:
Setup Raspberry Pi as a server step by step
 Raspberry Pi as a server
If you want to set up Raspberry Pi as a server, then use it in the headless mode, then depending on individual preferences to make some configuration steps.
The following step-by-step guide is a suggestion to set up Raspberry Pi as a server.

The order of the individual steps follows an internal logic. So a repeated reboots should be avoided and only take place if there is no other way. Of course you can also change the order or omit individual steps if you do not need them.

The instructions provide that you can make the configuration via SSH. But this requires an active SSH server on Raspberry Pi. Of course, the configuration can also be done locally.

  • Choice of distribution
  • installation
  • commissioning
  • Make basic configuration
  • Change default password
  • Change boot options
  • Change host name
  • Create new SSH keys
  • Expand file system
  • Update packages
  • install a software
  • Create user
  • Basic configuration of the SSH server
  • Additional security measures (optional)
  • Network Configuration
  • Complete the configuration
Choice of distribution
With a server, one will usually opt for a minimal image, because any pre-installed software is redundant, unnecessarily consumes storage space and also includes performance and security risks.
  • Inserting the SD memory card
  • Connecting the screen and keyboard
  • Connecting the network cable
  • Connecting the power supply

Make basic configuration
The first steps are to set the country, language, and time settings.

Set system language, location and character set:
 sudo dpkg-reconfigure locales

Set time zone:
 sudo dpkg-reconfigure tzdata

Set keyboard layout (not via SSH):
 sudo dpkg-reconfigure keyboard-configuration

Or if you want to set it via SSH:
 sudo nano / etc / default / keyboard

Here you change the following value:

Note: Depending on the distribution, there are different ways to make these basic settings. So under Raspbian there is the tool "raspi-config", with which the above settings can be carried out very comfortably.
 sudo raspi-config

Change default password
For safety reasons, the default password must be changed as soon as possible after the first commissioning. Usually immediately. In this case, only after the language settings, because then you have a German-speaking user interface, which simplifies the handling.

The password of the user "pi" can also be changed via "raspi-config".

The new password must be entered and confirmed "blindly".

Boot Options
Raspbian Wheezy starts the console by default. Then you have to log in. Under Raspbian Jessie the graphical user interface is started by default, which we do not necessarily want. These boot options are best set with the tool "raspi-config".
 sudo raspi-config

Change host name / computer name
By default, a fresh image of a Linux distribution has a given hostname. In a server operation you might want to give an individual host name.
 sudo hostname -b {NEWNAME}

Or via "raspi-config".

Then briefly check:

It may not be enough. One should take another look at the hosts file.
 cat / etc / hosts

If there is still the old host name in it, then you have to change the file in this file too.
 sudo nano / etc / hosts

Then save and close: Ctrl + O, Return, Ctrl + X.

Create new SSH keys
At the latest, if you have changed the hostname, you have to create new SSH keys. First we delete all the files in which the keys are located. There are several of them. Nevertheless, a command is sufficient for deletion.
 sudo rm / etc / ssh / ssh_host_ 

Afterwards, we perform a reconfiguration of the SSH server:
 sudo dpkg-reconfigure openssh-server

The creation of the key files is automatic. Normally, the SSH server should also be restarted automatically. If not, then you have to do it manually.
 sudo service ssh restart

It is not necessary to restart the system. However, one must note that after a new login via SSH, the identity of the system must be reconfirmed.

Expand file system
If a Linux distribution has just been written to an SD card, then not all of the memory card will be used, only part of it. If you want to extend the file system to the whole memory card, then we recommend the menu item "Expand Filesystem" via "raspi-config".
Subsequently, a reboot is mandatory.
 sudo reboot

Note: After an "expand file system", a reboot must be mandatory. If you continue here without reboot, you can shoot the system.

Update packages
When rebuilding a system, it's a good idea to check the repositories that will later be used to package new and updated packages through package management. Depending on what requirements you make, adjustments may or may not be necessary.

If you use a standard distribution like Raspbian, checking the package sources is not mandatory. They are mostly sensible. It looks different when you have an image from a foreign source. Here you should take a look.
Then we perform the update of the package lists from the package sources.
 sudo apt-get update

And then we load and install updated packages.
 sudo apt-get upgrade

Depending on the timeliness of the image or the distribution that can sometimes take a little longer.
install a software
Depending on the distribution or image, it may not hurt to install a few packages. These are a few tools that will help you better use the system later.

The installation is done individually. That means, if necessary, individual packages can be omitted or later installed.
 apt-get install sudo

Create user
The following steps are only valid if no user has been set up yet. With Raspbian the user "pi" is already set up and therefore no further user has to be set up.

It makes sense to set up another user for administration only if the "sudo" package was previously installed.

Set up users with home directory:
 useradd -m {USERNAME}

To set a password:
 passwd {USERNAME}

Then the password must be entered "blind" and then confirmed.

Assign default bash:
 usermod -s / bin / bash {USERNAME}

Assign main group:
 usermod -g users {USERNAME}

Assign user groups:
 gpasswd -a {USERNAME} sudo

gpasswd -a {USERNAME} ssh

Check group membership of a user:

Test new user:
 su - {USERNAME}

End user:

Set authorization for the user group "sudo":

Here we check whether the following line is entered. If not, then this line must be added.
 $ sudo ALL = (ALL: ALL) ALL

Having set up a user for system administration is a good opportunity to test it by logging in. To do this, log in as "root" and as a new user.

Basic configuration of the SSH server
The next step is to configure the SSH server more securely.
 sudo nano / etc / ssh / sshd_config

The following lines must be considered individually. In some cases, the parameters are already correctly preset. Others must be changed or added later.

 rotocol 2

 AllowGroups ssh

 PermitEmptyPasswords no

 PermitRootLogin no

After the changes, the file must be saved and closed. Afterwards a restart of the SSH server is necessary, so that the changes are taken over.
 sudo service ssh restart

An existing SSH connection is not interrupted.

Additional security measures (optional)
If you have set up a user for system administration who is authorized to use "sudo" and can connect via SSH, then you can further improve the security of the entire system by deleting the password of "root".
 sudo passwd -d root

Network Configuration
Before the configuration of the entire system is completed, it will still take care of the network configuration. However, this is to be determined individually. So you will usually set up a static IPv4 address for server operation. In one case or another, enable IPv6, which is recommended for a new setup. And if necessary, you will install additional network services, such as Avahi.
Complete the configuration
The last restart. This is necessary to know that when you restart, everything really works the way you want it to.
 sudo reboot
Overview: Raspberry Pi as a server
Overview: Remote maintenance and remote service
Share it:

Raspberry Pi

Post A Comment: