Skip to navigation

Change default settings

There are a number of settings which people often change when they have just installed Linux.

Stop Raspbian from booting to the desktop

If  you are using your Banana Pi as a server, you may not need to use the Lightdm desktop environment, and just let your Banana Pi boot to a command line interface.  

When Raspbian boots, it executes scripts in /etc/init.d to start various services, including Lightdm.  You can use the update-rc.d command to prevent any of these scripts from running. This command stops Lightdm from running when you boot your Pi:

sudo update-rc.d -f lightdm remove

If you wish to start a desktop session from the command line, use this command:

sudo service lightdm start

If you want Lightdm to start on boot up again, use this command:

sudo update-rc.d -f lightdm defaults

Change the default username

Many Linux images have a default username and password.  The default username and password for the Raspbian image are 'pi' and 'bananapi' (in many of the Banana Pi Linux distributions, the default username is bananapi).  It's best to change these login details so that no one else can log into your Pi. 

You need to configure your Pi to boot to a command line - the following procedure won't work if you're logged into a desktop session.  Once you've booted to a command line, you need to change the shell session to the root user.  This is necessary because you can't modify a user account while you're logged in as that user.

exec sudo -s

Now all commands are executed as the root user. Change to a different directory than /home/pi:

cd /

Use the usermod command to change username of the default account

usermod -l steve -d /home/steve -m pi

When you reboot, you'll need to log in using the new user name.

Change the default password

One of the most important things to change is the password.  Using the default password is a monumental security risk.  The default password for most Banana Pi Linux distributions is simply bananapi. Change it using the passwd command:

passwd
Changing password for steve.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:

You will be prompted to enter your current password, followed by your new password twice.

Change the hostname

The hostname is the name of your server as it appears on your local network.  You may need to change the hostname if you have more than one Banana Pi on your network. You'll need to change it in two places:

  1. /etc/hostname
  2. /etc/hosts

The hostname is set in /etc/hostname.  This file only contains the hostname.  Open it as root, and change the name.  I've change it from 'lemaker' to 'bpi'. 

In /etc/hosts, there's a list of IP addresses and their host names.  This file contains a table mapping IP addresses to host names.  Open it with this command:

sudo nano /etc/hosts

Look for an entry with IP address 127.0.1.1, and change the host name as required.

127.0.0.1    localhost
::1        localhost ip6-localhost ip6-loopback
fe00::0        ip6-localnet
ff00::0        ip6-mcastprefix
ff02::1        ip6-allnodes
ff02::2        ip6-allrouters

127.0.1.1    bpi

Reboot your Banana Pi, and you should see that its host name has changed.

Update SSH keys

If you're using a version of Linux installed from an image, the image may already contain keys. These keys are the same for anyone who's installed the same image, so it's important to change them.

There are keys that the ssh server daemon uses to authenticate incoming connections, which need to be removed:

sudo rm /etc/ssh/ssh_host_*

Now create new keys:

sudo dpkg-reconfigure openssh-server

A new set of ssh keys will be generated in /etc/ssh.

Generate user ssh keys

Users can generate ssh keys for themselves so that they can easily authenticate with ssh servers on other hosts.  Using keys means users can be identified by their keys without needing to type a password.

Create a folder in my hom folder to store inthe keys:

mkdir ~/.ssh
chmod 700 ~/ssh

Generate the keys:

ssh-keygen -t rsa -C steve@bpi

You'll be prompted for a place to save the keys.  Just press return to use the default location. This will create a pair of RSA key files in ~/.ssh/.

The public key must be transferred to any device I wish to log into with ssh.  For example, if I wanto to log into another Linux host at IP address 192.168.0.3 as user dave, I would use this sequence of commands to transfer the public key:

cat ~/.ssh/id_rsa.pub | ssh dave@192.168.0.3 'cat >> ./.ssh/authorized_keys'

It's necessary to type a password the first time the connection is made, but after that it's possible to connect to this device without typing a password.

Share this page:

comments powered by Disqus