Raspberry Pi Server - Part 0: Setup and ssh access

in it •  7 years ago 

======================================

This is first part of a series for people who ever would like to experiment with server systems, or always wanted to setup their own cheap Linux server at home. Raspberry Pis are not reliable enough for production systems, but they are good enough to get experience with Linux systems and deployment of tiny web services and web sites.

Please feel free to comment.
Enjoy!

======================================

Setup your Raspberry Pi to be used via SSH

For this you will need following hardware:

  1. Raspberry Pi (I use a Raspberry Pi 3 Model B with a clear case and heat sinks)
  2. MicroSD (I use a 32GB SanDisk)
  3. Micro USB Power Source (5V, 2.5A should do)
  4. Ethernet Cable
  5. Peripherals for one time setup: Keyboard, Mouse, Screen and HDMI-cable

And following software:

  1. Jessie lite image (https://www.raspberrypi.org/downloads/raspbian/)
  2. Win32diskimage (http://www.raspberry-projects.com/pi/pi-operating-systems/win32diskimager), or any other imager
  3. git bash (install git from https://git-scm.com/downloads)

Preparations: Get your Raspberry Pi ready

First, we need to setup Raspbian on our Pi. Get the Jessie Lite image from https://www.raspberrypi.org/downloads/raspbian/

Jessie_Lite.PNG

There are several software solutions for write an image to an SD card. I used the win32diskimager.

1_diskimager.PNG

Run the imager, and carefully select the drive you want to write your image to and the jessie lite image you just downloaded from the raspberrypi site.

(Hint: In case you would like to set up multiple Raspberry Pis in the same way, the diskimager also can read an image. Once your raspberry pi is set up completely, you can make a backup of it, and even write the same image on multiple new MicroSD cards, when can then be used in other Raspberry Pis)

Once the image is written to your MicroSD card, safely eject your MicroSD card and insert it into your unpowered Raspberry pi.

IMG_20170628_224822_small.jpg

IMG_20170628_224846_small.jpg

I got a clear case for my raspberry and some heat sinks

Starting up the Raspberry Pi for the first time

Plug in all peripherals (screen, mouse, keyboard) and power up your Raspberry Pi.

After the starting up process, you will be greeted with the login prompt:

login_small.jpg

The default login is:
user: pi
password: raspberry
(Hint: Watch out for keyboard language settings)

Once we are logged in successfully, we get the next prompt:
first_login_success_small.jpg

Now we can get started to change the configurations of the Raspberry Pi.

Setting the Pi's configurations

Expand Filesystem

The first thing we will change is to make sure that the entire SD card is available to the OS.

to enter the configurations menu, type:

sudo raspi-config

now choose: Advanced Options
and finally: Expand Filesystem

Once you finished, you will be informed that the filesystem will be resized upon the next reboot.
Finish with OK, we still have some settings to set.

Enable SSH

Next, we will enable remote access to the raspberry via SSH.
For safety reasons SSH is disabled by default, so we will have to change that.

choose: Interfacing Options
and: SSH

Here you can enable SSH for our Raspberry Pi, which we will need in future.

Change password

Finally we will set a new password to our raspberry pi, just to make sure nobody can access the pi account.

choose: Change User Password

The pi user is a Sudoer, which means it can call commands with root permission. In the wrong hands, this could be abused to turn our nice Raspberry Pi Sudoer user into an Evildoer machine. (Bad joke, sorry)
More information about Linux users can be found here:
https://www.raspberrypi.org/documentation/linux/usage/users.md

Once these three changes are done, shutdown your raspberry pi with following command:
sudo shutdown -h now

Connect to Router and first SSH login

Physically connect your Raspberry Pi to the Router

Now take your Raspberry Pi, you can unplug all cables and peripherals.
You will only need your Ethernet cable and your Micro USB Power supply.

Go to your router, connect your Raspberry Pi via Ethernet and start it up by plugging in the power supply.

From this point on, we should not need to touch our Raspberry Pi ever again physically if things go right.

Find the Raspberry on the Network

To ssh into our Raspberry Pi, we need to find out its IP address, and there are several ways to find it.
I recommend installing git, which will allow us to use git bash in the future.
Also, in the future we would like to have our own private git repository on our little server.

I prefer to use nmap for it.

nmap is an available command in git bash by default. After installing git, right click anywhere in a directory and run git bash.

Now check your standard gateway, this is the ip address of your router. Mine is 192.168.0.1, so I will use nmap to look for all devices connected in this network with:
nmap -sP 192.168.0.0/24

Among other devices, it also shows my Raspberry Pi at the address 192.168.0.136

FindRaspberryIp.PNG

Login via SSH

After finding out the IP Address, we can login to our Raspberry via SSH:
ssh [email protected]

This means that we will login as the user pi.

At your first login attempt, you need to confirm the authenticity of the host:
Raspberry_first_login_athenticity_host.PNG

Now your git bash terminal is your terminal to the Raspberry Pi', and you can give commands which will be executed by the Raspberry Pi.

In case you did not change the password, you will see a warning, and this is the time when you really should choose a new password for the pi user.

For today, this is how far we go.

To finish the ssh connection, you can simply type:
CTRL+D
or just type:
logout

Raspberry_Logout.PNG

This will close the connection, and your git bash will turn back to normal.

Next time I will go through the process of generating ssh keys, disabling password login to have a somewhat safe way to open the raspberry to the outside world, so we can ssh to our Raspberry Pi Server from anywhere, anytime.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Thanks!

Maybe i should write a description how to make bots leaving 2 word comments on posts they find.
And maybe, as a follow up, how to make bots which upvote each other's 2 word posts.

What do you think?

Ja, also ich hab mich jetzt schon viel mit den Botmöglichkeiten gespielt, und es gibt tatsächlich viele und die machen auch schnell viel reputation mit solchen "thank you's". Ich kann nicht einschätzen wie "detremental" das für die Platform ist, weil es gibt hier ja schon sowas wie ne community, aber es wird glaub ich mit der Zeit nicht besser werden. Hab jetzt in den letzten 10 Tagen jeden Tag was kurzes gepostet, aber bin nicht sicher ob man nicht momentum erreichen kann - wenn das das ziel ist - ohne recht weit runter zu gehn in Sachen lowest denominator. Die programmiercommunity (tags "programming" und "steemdev") ist denk ich, vermutlich, guten Willens, aber noch zu klein.