Most of the instructions in the category requires privileges of a superuser or the root user. If otherwise, the account to perform all instructions must be preceded with a sudo command. To avoid using sudo, please log in as a superuser first. All instruction collected in this category assumes a superuser. You can log in as a superuser if the account you log in is a sudoer. The system might not ask for a password if the account is NOPASSWD-enabled.
$ sudo -i
pi password: raspberrypi
If not, you must have the root password to gain superuer privileges.
$ su root
Password: root_password
It is advised to create a unique user and delete the default user pi for security purpose. To create a user, or delete a user. The option rfRZ shown below deletes the user and its home directory.
$ useradd user_name
$ userdel -rfRZ user_name
To set or change password of a user:
$ passwd user_name
Enter new UNIX password: new_password
Retype new UNIX password: new_password
To find out group_name from the system, or the groups where a user belongs:
$ groups
sudo admin users ....
$ groups user_name
To add a user to a group or the sudo group, or delete it from the group:
$ adduser user_name sudo
$ deluser user_name group_name
$ usermod -aG group_name user_name
To completely remove the user:
$ userdel -r user_name
To allow a particular sudoer to sudo a command without a password, create a file, eg. 01_user, in /etc/sudoers.d direcoty. The file can contain a line below to enable NOPASSWD fo the user_name account:
user_name ALL=(ALL) NOPASSWD:ALL
To see the storage space available in the SD disk,
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       7.3G  1.7G  5.3G  24% /
/dev/mmcblk0p1   43M   22M   21M  51% /boot

$ fdisk -l
Device         Boot Start      End  Sectors  Size Id Type
/dev/mmcblk0p1       8192    96663    88472 43.2M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      98304 15523839 15425536  7.4G 83 Linux
After hardware setup of the unit, it is good to look through its default settings first. To display the hostname:
$ hostname
raspberrypi
To display the IP address:
$ hostname -I
192.168.1.80
The command ifconfig can be used to display more details. It shows details of hard-wired or wireless network connection with an option of eth0 or wlan0, respectively.
$ ifconfig
$ ifconfig wlan0
$ ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
   inet 192.168.1.80 netmask 255.255.255.0 broadcast 192.168.1.255
   ...
The unit must have a static IP address to be a web server. If the router uses a dhcp service to dynamically assigns an IP address to the unit, it is better to make it static. Temporarily, the following commands can set the IP:
$ ifconfig eth0 192.168.1.80 netmask 255.255.255.0
$ route add default gw 192.168.1.254
The instruction below assumes a superuser (c.f. superuser - sudo). To fix a permanent static IP address for the unit, first locate the configuration file, and use the built-in editor nano to edit the file.
$ nano /etc/dhcpcd.conf
Then modify the lines in the configuration file if they exist (or add them if they don't) like the hard-wired example below:
interface eth0 static ip_address= 192.168.1.80 static routers= 192.168.1.1 static domain_name_servers= 192.168.1.1 10.30.1.1
For Wi-Fi, change eth0 to wlan0 above. The IP addresses in the example above must be replaced with your own. Once completed, hit Ctrl-X and Y to exit the editor and save the changes. The unit must be reboot for the static IP address to take effect.
$ reboot

Profimation Inc. & Bodhist.net
blog@profimate.com
  +(886) 2-3322-9780
Total visits: 80666