<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Raspberry Pi on KTDEVX</title><link>/en/tags/raspberry-pi/</link><description>KTDEVX (Raspberry Pi)</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>ktdevx@gmail.com
(Kaito Takemura)</managingEditor><lastBuildDate>Mon, 30 Sep 2024 00:41:00 +0900</lastBuildDate><atom:link href="/en/tags/raspberry-pi/index.xml" rel="self" type="application/rss+xml"/><item><title>Build a Git Server at Home with a Raspberry Pi</title><link>/en/blog/setup-git-server-on-raspberry-pi/</link><pubDate>Mon, 30 Sep 2024 00:41:00 +0900</pubDate><author>ktdevx@gmail.com (Kaito Takemura)</author><guid>/en/blog/setup-git-server-on-raspberry-pi/</guid><description>&lt;p>Building a Git server at home is useful when you do not want to publish your source code or want to customize the server yourself.&lt;/p>
&lt;p>Let&amp;rsquo;s build a Git server using a Raspberry Pi, which is inexpensive and has extensive documentation available online.&lt;/p>
&lt;h2 id="network-configuration" >
&lt;div>
&lt;a href="#network-configuration">
#
&lt;/a>
Network Configuration
&lt;/div>
&lt;/h2>
&lt;p>The network configuration is as follows.&lt;/p>
&lt;p>&lt;img alt="Network configuration" src="https://www.ktdevx.com/ja/blog/setup-git-server-on-raspberry-pi/images/git-server-network.webp">&lt;/p>
&lt;p>A Git server is built on the Raspberry Pi so that PCs on the same network can access it.&lt;/p>
&lt;h2 id="prepare-the-raspberry-pi" >
&lt;div>
&lt;a href="#prepare-the-raspberry-pi">
#
&lt;/a>
Prepare the Raspberry Pi
&lt;/div>
&lt;/h2>
&lt;h3 id="install-the-os" >
&lt;div>
&lt;a href="#install-the-os">
##
&lt;/a>
Install the OS
&lt;/div>
&lt;/h3>
&lt;p>First, install an OS on the Raspberry Pi. A GUI is unnecessary for a server, so Raspberry Pi OS Lite is installed in this example.&lt;/p>
&lt;p>Raspberry Pi OS Lite is an OS for Raspberry Pi devices and can be downloaded from the official website. Detailed installation instructions are available on the Raspberry Pi &lt;a href="https://www.raspberrypi.com/">official website&lt;/a>.&lt;/p>
&lt;h3 id="set-a-static-ip-address" >
&lt;div>
&lt;a href="#set-a-static-ip-address">
##
&lt;/a>
Set a Static IP Address
&lt;/div>
&lt;/h3>
&lt;p>Assign a static IP address so that the Raspberry Pi can always be accessed at the same address.&lt;/p>
&lt;p>Run the following command to change the IP address settings.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo vi /etc/dhcpcd.conf
&lt;/code>&lt;/pre>&lt;p>When the text editor starts, append the following to the file.&lt;/p>
&lt;pre tabindex="0">&lt;code>interface eth0
static ip_address=192.168.0.2/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1
&lt;/code>&lt;/pre>&lt;p>This example specifies an IP address of &lt;code>192.168.0.2&lt;/code>, a subnet mask of &lt;code>255.255.255.0&lt;/code>, and &lt;code>192.168.0.1&lt;/code> as the default gateway and DNS server.&lt;/p>
&lt;p>Save the file and restart the Raspberry Pi with the following command.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo reboot
&lt;/code>&lt;/pre>&lt;p>The IP address is now static.&lt;/p>
&lt;h3 id="enable-the-ssh-server" >
&lt;div>
&lt;a href="#enable-the-ssh-server">
##
&lt;/a>
Enable the SSH Server
&lt;/div>
&lt;/h3>
&lt;p>Enable SSH access so that you can connect to the Raspberry Pi over SSH. Detailed instructions are available in the following article.&lt;/p>
&lt;p>&lt;a href="https://www.ktdevx.com/en/blog/enable-ssh-on-raspberry-pi-os/">Enable SSH Access on Raspberry Pi OS&lt;/a>&lt;/p>
&lt;h2 id="install-git" >
&lt;div>
&lt;a href="#install-git">
#
&lt;/a>
Install Git
&lt;/div>
&lt;/h2>
&lt;p>Run the following commands to install Git on the server.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo apt update
sudo apt install git
&lt;/code>&lt;/pre>&lt;p>Git is now installed on the server.&lt;/p>
&lt;h2 id="add-the-git-user-and-create-a-directory" >
&lt;div>
&lt;a href="#add-the-git-user-and-create-a-directory">
#
&lt;/a>
Add the Git User and Create a Directory
&lt;/div>
&lt;/h2>
&lt;p>Create a user named &lt;code>git&lt;/code> on the server for Git operations.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo adduser git
&lt;/code>&lt;/pre>&lt;p>When prompted for a password, enter one of your choice and press Enter. Enter the same password again when prompted. The &lt;code>git&lt;/code> user is created.&lt;/p>
&lt;p>Next, create a directory to store Git repositories.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo mkdir /opt/git
sudo chown git:git /opt/git
&lt;/code>&lt;/pre>&lt;p>These commands create a directory named &lt;code>git&lt;/code> under &lt;code>/opt&lt;/code> and change its owner to the &lt;code>git&lt;/code> user. This allows the &lt;code>git&lt;/code> user to read and write Git repositories created under &lt;code>/opt/git&lt;/code>.&lt;/p>
&lt;p>From this point on, perform operations on the server as the &lt;code>git&lt;/code> user. Switch users with the following command.&lt;/p>
&lt;pre tabindex="0">&lt;code>su git
&lt;/code>&lt;/pre>&lt;h2 id="register-an-ssh-public-key" >
&lt;div>
&lt;a href="#register-an-ssh-public-key">
#
&lt;/a>
Register an SSH Public Key
&lt;/div>
&lt;/h2>
&lt;p>Generating an SSH key enables secure communication with the Git server. Register a public key so that you can access the Git server over SSH.&lt;/p>
&lt;p>Run the following command on the PC to generate an SSH key.&lt;/p>
&lt;pre tabindex="0">&lt;code>ssh-keygen
&lt;/code>&lt;/pre>&lt;p>Press Enter to generate the key using the default settings. With the default settings, a private key named &lt;code>id_rsa&lt;/code> and a public key named &lt;code>id_rsa.pub&lt;/code> are generated in the &lt;code>.ssh&lt;/code> directory.&lt;/p>
&lt;p>To access the server over SSH, register the public key on the server. Transfer the public key you generated to the server using FTP or SFTP.&lt;/p>
&lt;p>After transferring the public key, create a file named &lt;code>authorized_keys&lt;/code> under the &lt;code>.ssh&lt;/code> directory and register the public key in it. Run the following commands on the server to create &lt;code>authorized_keys&lt;/code>.&lt;/p>
&lt;pre tabindex="0">&lt;code>cd
mkdir .ssh &amp;amp;&amp;amp; chmod 700 .ssh
touch .ssh/authorized_keys &amp;amp;&amp;amp; chmod 600 .ssh/authorized_keys
&lt;/code>&lt;/pre>&lt;p>An empty &lt;code>authorized_keys&lt;/code> file is created. Add the public key you generated earlier to this file.&lt;/p>
&lt;pre tabindex="0">&lt;code>cat &amp;lt;directory-containing-public-key&amp;gt;/id_rsa.pub &amp;gt;&amp;gt; ~/.ssh/authorized_keys
&lt;/code>&lt;/pre>&lt;p>The public key is now added to &lt;code>authorized_keys&lt;/code>.&lt;/p>
&lt;h2 id="create-a-git-repository" >
&lt;div>
&lt;a href="#create-a-git-repository">
#
&lt;/a>
Create a Git Repository
&lt;/div>
&lt;/h2>
&lt;p>Run the following commands to create a repository on the Git server.&lt;/p>
&lt;pre tabindex="0">&lt;code>mkdir /opt/git/project.git
cd /opt/git/project.git
git init --bare
&lt;/code>&lt;/pre>&lt;p>This example creates a Git repository named &lt;code>project.git&lt;/code>.&lt;/p>
&lt;p>Running &lt;code>git init&lt;/code> with the &lt;code>--bare&lt;/code> option creates an empty repository without a working directory. This is called a bare repository.&lt;/p>
&lt;p>By convention, a bare repository directory name ends with &lt;code>.git&lt;/code>.&lt;/p>
&lt;h2 id="clone-the-git-repository" >
&lt;div>
&lt;a href="#clone-the-git-repository">
#
&lt;/a>
Clone the Git Repository
&lt;/div>
&lt;/h2>
&lt;p>Run the following command to clone the repository.&lt;/p>
&lt;pre tabindex="0">&lt;code>git clone git@192.168.0.2:/opt/git/project.git
&lt;/code>&lt;/pre>&lt;p>You have now built a Git server at home using a Raspberry Pi.&lt;/p></description></item><item><title>Install Ubuntu on a Raspberry Pi</title><link>/en/blog/install-ubuntu-on-raspberry-pi/</link><pubDate>Mon, 30 Sep 2024 00:26:00 +0900</pubDate><author>ktdevx@gmail.com (Kaito Takemura)</author><guid>/en/blog/install-ubuntu-on-raspberry-pi/</guid><description>&lt;p>In addition to Raspberry Pi OS, you can also boot Ubuntu on a Raspberry Pi.&lt;/p>
&lt;p>This article explains how to install Ubuntu on a Raspberry Pi.&lt;/p>
&lt;h2 id="install-raspberry-pi-imager" >
&lt;div>
&lt;a href="#install-raspberry-pi-imager">
#
&lt;/a>
Install Raspberry Pi Imager
&lt;/div>
&lt;/h2>
&lt;p>Install a tool called Raspberry Pi Imager to write Ubuntu to a microSD card.&lt;/p>
&lt;p>Download the tool from the &lt;a href="https://www.raspberrypi.com/software/">official website&lt;/a> and install it on your PC.&lt;/p>
&lt;h2 id="write-ubuntu-to-a-microsd-card" >
&lt;div>
&lt;a href="#write-ubuntu-to-a-microsd-card">
#
&lt;/a>
Write Ubuntu to a microSD Card
&lt;/div>
&lt;/h2>
&lt;p>Write Ubuntu to a microSD card. Insert the microSD card into your PC and launch Raspberry Pi Imager.&lt;/p>
&lt;p>&lt;img alt="Raspberry Pi Imager" src="https://www.ktdevx.com/ja/blog/install-ubuntu-on-raspberry-pi/images/raspberry-pi-imager-1.webp">&lt;/p>
&lt;p>Select OS, Other general-purpose OS, and Ubuntu in that order to display the list of Ubuntu versions available for installation.&lt;/p>
&lt;p>&lt;img alt="Raspberry Pi Imager" src="https://www.ktdevx.com/ja/blog/install-ubuntu-on-raspberry-pi/images/raspberry-pi-imager-2.webp">&lt;/p>
&lt;p>Select the OS you want to install.&lt;/p>
&lt;p>After selecting the OS, select the microSD card to which you want to write Ubuntu from Storage.&lt;/p>
&lt;p>&lt;img alt="Raspberry Pi Imager" src="https://www.ktdevx.com/ja/blog/install-ubuntu-on-raspberry-pi/images/raspberry-pi-imager-3.webp">&lt;/p>
&lt;p>If the OS and storage selections are correct, select Write to start writing the image.&lt;/p>
&lt;p>&lt;img alt="Raspberry Pi Imager" src="https://www.ktdevx.com/ja/blog/install-ubuntu-on-raspberry-pi/images/raspberry-pi-imager-4.webp">&lt;/p>
&lt;p>Wait a while for the writing process to complete.&lt;/p>
&lt;h2 id="boot-ubuntu" >
&lt;div>
&lt;a href="#boot-ubuntu">
#
&lt;/a>
Boot Ubuntu
&lt;/div>
&lt;/h2>
&lt;p>Insert the microSD card containing Ubuntu into the Raspberry Pi and turn it on.&lt;/p>
&lt;p>When prompted to log in, enter &lt;code>ubuntu&lt;/code> as the username and password.&lt;/p>
&lt;pre tabindex="0">&lt;code>Ubuntu 22.04.2 LTS ubuntu tty1
ubuntu login: ubuntu
Password:
&lt;/code>&lt;/pre>&lt;p>On the first login, you are prompted to change the password. Enter a new password of your choice.&lt;/p>
&lt;pre tabindex="0">&lt;code>You are required to change your password immediately (administrator enforced).
Changing password for ubuntu.
Current password:
New password:
Retype new password:
&lt;/code>&lt;/pre>&lt;p>Ubuntu is now ready to use on the Raspberry Pi.&lt;/p></description></item><item><title>Enable SSH Access on Raspberry Pi OS</title><link>/en/blog/enable-ssh-on-raspberry-pi-os/</link><pubDate>Mon, 30 Sep 2024 00:16:27 +0900</pubDate><author>ktdevx@gmail.com (Kaito Takemura)</author><guid>/en/blog/enable-ssh-on-raspberry-pi-os/</guid><description>&lt;p>Raspberry Pi OS is an operating system for Raspberry Pi devices provided by the Raspberry Pi Foundation. Enabling SSH access allows you to access your Raspberry Pi remotely.&lt;/p>
&lt;p>This article explains how to enable SSH access on Raspberry Pi OS.&lt;/p>
&lt;h2 id="launch-the-configuration-tool" >
&lt;div>
&lt;a href="#launch-the-configuration-tool">
#
&lt;/a>
Launch the Configuration Tool
&lt;/div>
&lt;/h2>
&lt;p>Run the following command to launch the Raspberry Pi configuration tool.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo raspi-config
&lt;/code>&lt;/pre>&lt;h2 id="enable-the-ssh-server" >
&lt;div>
&lt;a href="#enable-the-ssh-server">
#
&lt;/a>
Enable the SSH Server
&lt;/div>
&lt;/h2>
&lt;p>&lt;img alt="raspi-config" src="https://www.ktdevx.com/ja/blog/enable-ssh-on-raspberry-pi-os/images/raspi-config-1.webp">&lt;/p>
&lt;p>After running the command, the configuration screen is displayed. Move the cursor to Interface Options and press Enter.&lt;/p>
&lt;p>&lt;img alt="raspi-config" src="https://www.ktdevx.com/ja/blog/enable-ssh-on-raspberry-pi-os/images/raspi-config-2.webp">&lt;/p>
&lt;p>The interfaces for which you can enable or disable settings are displayed. Move the cursor to SSH and press Enter.&lt;/p>
&lt;p>&lt;img alt="raspi-config" src="https://www.ktdevx.com/ja/blog/enable-ssh-on-raspberry-pi-os/images/raspi-config-3.webp">&lt;/p>
&lt;p>You are asked whether to enable the SSH server. Select Yes.&lt;/p>
&lt;p>&lt;img alt="raspi-config" src="https://www.ktdevx.com/ja/blog/enable-ssh-on-raspberry-pi-os/images/raspi-config-4.webp">&lt;/p>
&lt;p>The SSH server is enabled. Press Enter to return to the top of the configuration screen.&lt;/p>
&lt;p>&lt;img alt="raspi-config" src="https://www.ktdevx.com/ja/blog/enable-ssh-on-raspberry-pi-os/images/raspi-config-5.webp">&lt;/p>
&lt;p>Select Finish to close the configuration tool.&lt;/p>
&lt;h2 id="restart-the-ssh-server" >
&lt;div>
&lt;a href="#restart-the-ssh-server">
#
&lt;/a>
Restart the SSH Server
&lt;/div>
&lt;/h2>
&lt;p>Run the following command to restart the SSH server.&lt;/p>
&lt;pre tabindex="0">&lt;code>sudo systemctl restart ssh
&lt;/code>&lt;/pre>&lt;p>SSH access is now enabled on Raspberry Pi OS. You can access the Raspberry Pi remotely over SSH from another computer.&lt;/p></description></item></channel></rss>