[LINUX] Server construction procedure Ubuntu18.04 server

A note on server construction.

1. linux setup

ISO preparation, install

Put the Ubuntu ISO file on a disk or put it on a USB. Then boot the server's BIOS and proceed with the install. As introduced in the link below, it's OK. Ubuntu installation procedure

root password setting

--Ubuntu default root user password is not set. ――Recently, I rarely use root, but just in case.

sudo passwd root

Enter the following commands in order.

sudo apt update
sudo apt upgrade
sudo reboot
sudo timedatectl set-timezone Asia/Tokyo
sudo apt -y install language-pack-ja
sudo nano /etc/default/locale
 # 「LANG=ja_JP.UTF-8 ”
sudo reboot
export LANG=C

2. Host-based authentication settings

windows10 setup

• teraterm • WinSCP Download WinSCP Impression that teraterm is basically enough. WinSCP plays an active role in sending files from the server side to the host.

Generate a pair of keys

Drag and drop id_rsa.pub to teraterm. Designated and transmitted as "~ /" by SCP. Start the server by selecting "File"-> "New Connection". Enter the following command

mkdir -p ~/.ssh
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
rm ~/id_rsa.pub
sudo vim /etc/ssh/sshd_config

Set up host-based authentication

First, change "no" to "yes" in "HostbasedAuthentication.no" on the 48th line. HostbasedAuthentication no HostbasedAuthentication yes

Line 56 # PasswordAuthentication Take # of yes and change yes to no PasswordAuthentication yes PasswordAuthentication no

After saving the setting file, to reflect the setting contents

sudo systemctl restart ssh

Do not close the currently connected Tera Term window, which will be explained next. (Because you need to fix it if it doesn't work)

3. Install samba

sudo apt update
sudo apt -y install samba
systemctl status smbd
systemctl status nmbd

Make sure it is active

Set up samba

sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.org
sudo vim /etc/samba/smb.conf

Samba smb.conf settings

/etc/samba/smb.conf


[global]
workgroup = SOTECHSHA
dos charset = CP932
unix charset = UTF8

[share]
comment = Ubuntu Server
path = /var/share
browsable = yes
writable = yes
create mask = 0777
directory mask = 0777

Execute the following command. adduser is a user who cannot log in for samba registration. It may be better to have a descriptive name when connecting.

sudo systemctl restart smbd
sudo systemctl restart nmbd
sudo mkdir /var/share
sudo chmod 777 /var/share
sudo adduser --disabled-login user1

User registration is OK with only full name and no input

Register user

sudo pdbedit -a user1

Connection method

\\(Server host name)
or
\\(IP address)

You can connect by entering the "user name" and "password" from.

4. Build a web server

Introducing apache

sudo apt update
sudo apt -y install apache2
ls /var/www/html
ls /etc/apache2
less /etc/apache2/apache2.conf

Run a web application

sudo a2enmod cgi
sudo systemctl restart apache2
cd /var/www/html
sudo vim cal.html

Edited to the following contents.

cal.html



<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8"> 
<title>input form</title>
</head>
<body>
<form action="cgi-bin/cal.sh" method="GET">
<h3>Please enter five numbers</h3>
<p>
Number 1: <input type="text" name="valuel" size="3"><br>
Number 2: <input type="text" name="value2" size="3"><br> 
Number 3: <input type="text" name="value3" size="3"><br> 
Number 4: <input type="text" name="value4" size="3"><br> 
Number 5: <input type="text" name="value5" size="3">
</p>
<p>
<input type="submit" value="Send"><input type="reset" value="reset"> 
</p>
</form>

Create a file.

cd /usr/lib/cgi-bin
sudo vim cal.sh

Edit the contents.

cal.sh



#! /bin/bash

SUM=0
VALUE=$ (echo ${QUERY_STRING} | tr '=&' " ¥n" | awk '{print $2}')
for i in ${VALUE}
do 
SUM=$((SUM + i))
done

cat << EOF
Content-type: text/html; charset=UTF-8
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8"> <title>Addition result</title>
</head>
<body>
<h3>If you add 5 numbers</h3>
<p>
${SUM}
</p>
</body>
</html>
EOF

Edit permissions

sudo chmod +x cal.sh

Access http: // Ubuntu Server IP address /cal.html

At the end

If I go further, I will add and edit. (As of October 01, 2020)

Recommended Posts

Server construction procedure Ubuntu18.04 server
NFS server construction
[Flutter] Ubuntu 20.04 environment construction
Ubuntu18.04 LTS minecraft server java edition construction memorandum
Build VNC Server on Ubuntu 20.04
Install Docker on Ubuntu Server 20.04
Install Ubuntu Server 20.04 on Btrfs
Laravel environment construction (Ubuntu 18.04 LTS)
[Windows] WSL2 + Ubuntu + Node.js environment construction
[Unity] Android development environment construction procedure
[Ubuntu] Installation procedure for Amazon Correto 8
[Ubuntu] Set up a Nukkit server
Rails on Docker environment construction procedure
CentOS8 + Anaconda 4.9.2 + jupyterhub environment construction procedure
Ubuntu Server 20.04.1 Autoinstall with USB boot
CentOS8 + Anaconda + Django development environment construction procedure
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Rails API server environment construction using docker-compose