วิธีติดตั้งระบบปฏิบัติการ Debian บน AWS EC2 วิธีการเชื่อมต่อผ่าน SSH บน VSCode การเพิ่ม Super User เข้าไปในกลุ่ม sudo และตกแต่งด้วย Oh-My-Zsh
ติดตั้ง Debian บน AWS EC2
AWS EC2
ล็อกอินเข้าไปที่ AWS เลือก EC2

Launch instance
ในหน้าจอ EC2 จะเห็นปุ่มสีส้ม Launch instance ให้คลิ๊กปุ่มนี้ครับ

เลือก Debian 10 ซึ่งมีอยู่ Debian เดียวครับ

RAM 4 GB
เนื่องจากผมต้องการทำโครงการ ติดตั้ง ERPNext บน Debian EC2 ซึ่งเขาแนะนำให้เตรียมหน่วยความจำ หรือ RAM อย่างน้อย 4 GB ผมจึงเลือกขนาดเซิร์ฟเวอร์เป็น t2.medium คลิ๊กปุ่ม Next: Configure Instance Details

หน้าจอถัดไปเป็นค่าปกติที่ AWS ตั้งเอาไว้ ผมปล่อยไว้ตามนั้นครับ คลิ๊กปุ่ม Next: Add Storage

Storage 16 GB
Add Storage ได้กำหนดค่าปกติไว้ที่ 8 GB

เนื่องจากผมต้องการใช้ Python3 จาก Anaconda จึงแนะนำให้เปลี่ยนเป็น 16 GB ครับ คลิ๊ก Next: Add Tags

Tags
การกำหนด Tag มีประโยชน์ในการตรวจสอบ ต้นทุน ที่ใช้ไปในแต่ละโครงการ ให้ใส่ชื่อโครงการตรง Value ครับ ตรง Key ใส่ Name พอเห็น Key: Value แล้วเราก็จะนึกออกว่ามันคือ Object นั่นเอง คลิ๊กปุ่ม Next: Configure Security Group

สำหรับการตั้งค่า Security Group เราสามารถเลือก Create a new security group ได้เลยครับ คลิ๊ก Review and Launch

ตรวจดูอีกครั้งครับ เพื่อความแน่ใจ ให้ตรวจอย่างน้อย 2 จุดครับ
- Memory ต้องไม่น้อยกว่า 4 GB
- Storage ต้องไม่น้อยกว่า 16 GB

Key pair
ตรงนี้สำคัญให้เลือก Key pair โดยต้องแน่ใจว่า เรามี private key file เก็บเอาไว้บนเครื่อง Local ไม่งั้นเราจะใช้คำสั่ง Remote ผ่าน SSH ไม่ได้ครับ ดูวิธีสร้าง Key pair หรือ ดูวิธีแก้เมื่อลืม Private key
เมื่อเลือก Key pair บน EC2 แล้ว ไม่สามารถเปลี่ยน Key pair ได้
คลิ๊กปุ่ม Launch

เมื่อมาถึงตรงนี้ เราสร้างเซิร์ฟเวอร์บน AWS EC2 เรียบร้อยแล้วครับ คลิ๊กปุ่ม View Instances

Elastic IPs
Instance ที่เราสร้างขึ้นสถานะ Pending แสดงว่ามันกำลัง Boot อยู่ครับ ยังไม่เรียบร้อยดี ระหว่างนี้ให้มองไปที่แถบเมนูด้านซ้ายมือตรง Network & Security เลือก Elastic IPs

แนะนำให้สร้าง Elastic IP ครับ เพราะไม่ว่าเราจะรีสตาร์ทเซิร์ฟเวอร์ซักกี่ครั้ง เรายังได้เลข IP เดิม ซึ่งจะเป็นประโยชน์ในการเชื่อมต่อเครื่อง Local ไปยัง Server ผ่าน SSH เมื่อมาถึงหน้านี้ ให้คลิ๊กปุ่ม Allocate Elastic IP address

มีข้อสังเกตนิดหนึ่งครับ การ Allocate Elastic IP address จะเป็นแบบ IPv4 นะครับ เท่าที่เห็นไม่มี IPv6
เมื่อมาถึงหน้านี้ เรากำหนด Tag เป็นชื่อโครงการของเราครับ แล้วคลิ๊กปุ่ม Allocate
เพื่อให้ AWS คิดต้นทุนเข้าแต่ละโครงการ เราจะได้คำนวณต้นทุนง่ายหน่อย

เสร็จแล้วเราจะได้เลข IP ครับ คลิ๊กตรงเลข IP สีฟ้าๆนะครับ

หน้าจอถัดมาให้คลิ๊กปุ่ม Associate Elastic IP Address

เลือก Instance บน EC2 ที่เราต้องการผูกไว้กับ Elastic IP ซึ่งก็คือ Instance ที่เราเพิ่งสร้างเมื่อกี้ครับ

ตอนนี้เลข Public IP จะเป็นเลขเดียวกับ Elastic IP นะครับ

เชื่อมต่อ SSH บน Browser ไม่ได้
ผมมีประสบการณ์การใช้งาน AWS EC2 ทั้งแบบ Ubuntu และ Debian ผมพบว่า Ubuntu สามารถเชื่อมต่อ SSH ผ่าน Browser ได้ เพียงคลิ๊กปุ่ม Connect ก็จะเข้าสู่หน้าจอ Terminal บน Browser

แต่สำหรับ Debian มันเชื่อมต่อ SSH บน Browser ไม่ได้ มันจะฟ้อง Error ตามรูปนี้ครับ

แต่ไม่เป็นไร เราสามารถเชื่อมต่อผ่าน VSCode แทนได้ครับ
ติดตั้ง VSCode Extensions
ให้ติดตั้ง VSCode Extensions เพิ่ม 2 ตัวครับ ตามรูป
Remote – SSH: Editing Configuration Files

และ Remote – SSH ซึ่งเป็นของ Microsoft ทั้งคู่ครับ

ก่อนใช้งาน Private Key
ไปที่โฟลเดอร์ที่ใช้เก็บ Private key บนเครื่อง local แล้วใช้คำสั่ง
chmod 400 <private key>
ในที่นี้จะเป็น
chmod 400 Node.pem

Bitnami แนะนำให้ใช้
chmod 600 <private key>

เชื่อม VSCode กับ EC2
EC 2
- ไปที่ AWS EC2 เลือก Instance ที่เราต้องการเชื่อมต่อกับ VSCode
- คลิ๊กปุ่ม Connect

- เลือกแท็บ SSH client

- คัดลอกตรงข้อ 4 ของแท็บ SSH client ตรงที่ผมทำลูกศรชี้ไว้ ให้คัดลอกทั้งบรรทัดครับ

VSCode บนเครื่อง Local
เปิดไฟล์ “/Users/<user-name>/.ssh/config” ด้วยคำสั่ง
code ~/.ssh/config
จะเห็นไฟล์เปล่า หรือถ้ามีข้อมูล ไฟล์จะมีหน้าตาแบบนี้ครับ

ให้เพิ่มโค้ดเข้าไปดังนี้ครับ
Host <Host-name>
HostName <Public DNS>
User admin
IdentityFile <path/to/private-key/privatekey.pem>
ในที่นี้จะเป็น
Host EC2-Tutorial-Debian-admin
HostName ec2-xx-xxx-xx5-50.ap-southeast-1.compute.amazonaws.com
User admin
IdentityFile /Users/manotlj/xxxx/Keys/Node.pem
ต่อไปให้คลิ๊กเครื่องหมาย settings ตรงมุมซ้ายล่าง

เลือกคำสั่ง Command Palette

Shortcut
หรือเข้าทาง Shortcut ก็ได้ครับ ตรงหัวมุมด้านซ้ายของ VSCode จะมีปุ่มสีเขียวๆ

ตรง Search area ให้พิมพ์ Remote-SSH แล้วเลือก Remote-SSH: Connect to Host…

จะมีรายชื่อ Remote Host ทั้งหมดที่อยู่ใน “~/.ssh/config” แสดงขึ้นมา เลือก Host ที่เราต้องการทำงาน ในที่นี้คือ EC2-Tutorial-Debian-admin

VSCode จะถามย้ำเรื่อง fingerprint

ให้เราตอบ Continue เสร็จแล้ว VSCode จะเข้ามาที่หน้าแรกตามรูปนี้ ให้คลิ๊ก Open Folder

หน้าจอ Trust จะขึ้นมา เพื่อให้เรายืนยัน

ติ๊กเครื่องหมายถูกตรง Trust the authors of all files … และคลิ๊กปุ่ม Yes, I trust the authors …

ไฟล์ที่อยู่บน EC2 เริ่มแรกจะมีแค่นี้ครับ

ผมเข้าใจว่าเครื่องมันเปิด Terminal ให้อัตโนมัติ ถ้ามันไม่เปิดให้ ไปเปิดที่ Terminal -> New Terminal

คำสั่งแรกคือ
sudo apt update && sudo apt upgrade -y
[email protected]:~$ sudo apt update && sudo apt upgrade -y
Hit:1 http://security.debian.org/debian-security buster/updates InRelease
Hit:2 http://cdn-aws.deb.debian.org/debian buster InRelease
Hit:3 http://cdn-aws.deb.debian.org/debian buster-updates InRelease
Hit:4 http://cdn-aws.deb.debian.org/debian buster-backports InRelease
Reading package lists... Done
Building dependency tree
Reading state information... Done
39 packages can be upgraded. Run 'apt list --upgradable' to see them.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
firmware-linux-free linux-image-4.19.0-17-cloud-amd64
...
...
...
Fetched 35.7 MB in 1s (48.9 MB/s)
apt-listchanges: Reading changelogs...
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LC_TERMINAL = "iTerm2",
LANG = "C.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("C.UTF-8").
...
...
...
Setting up curl (7.64.0-4+deb10u2) ...
Setting up libdns1104:amd64 (1:9.11.5.P4+dfsg-5.1+deb10u5) ...
Setting up libcurl3-gnutls:amd64 (7.64.0-4+deb10u2) ...
Setting up libisccfg163:amd64 (1:9.11.5.P4+dfsg-5.1+deb10u5) ...
Setting up libbind9-161:amd64 (1:9.11.5.P4+dfsg-5.1+deb10u5) ...
Setting up bind9-host (1:9.11.5.P4+dfsg-5.1+deb10u5) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for dbus (1.12.20-0+deb10u1) ...
Processing triggers for libc-bin (2.28-10) ...
Processing triggers for initramfs-tools (0.133+deb10u1) ...
update-initramfs: Generating /boot/initrd.img-4.19.0-17-cloud-amd64
[email protected]:~$
Setting locale failed
ในเบื้องต้นมันจะแจ้ง Warning ดังนี้ครับ
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = "UTF-8",
LC_TERMINAL = "iTerm2",
LANG = "C.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("C.UTF-8").
การตั้งค่าเบื้องต้นของ Debian เราต้องกำหนดค่า Locale เอง เราจะใช้ภาษาอะไรบ้างในการทำงาน เราก็ต้องแจ้ง Debian นิดหนึ่ง
ซึ่งในที่นี้จะใช้ 2 ภาษา คือ
- ภาษาอังกฤษ
- ภาษาไทย
แก้ Setting locale failed
ลองใช้คำสั่งต่อไปนี้ในการแก้ปัญหาครับ ลองทำทุกวิธีแล้วรีสตาร์ทครับ
- export
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
[email protected]:~$ export LANGUAGE=en_US.UTF-8
[email protected]:~$ export LANG=en_US.UTF-8
[email protected]:~$ export LC_ALL=en_US.UTF-8
- sudo dpkg-reconfigure locales
sudo dpkg-reconfigure locales
เครื่องจะเด้งหน้าจอนี้ขึ้นมาครับ

ให้เลือกภาษาที่เราต้องการในที่นี้จะเป็น
en_US.UTF-8 UTF-8

กดปุ่ม space bar เพื่อเลือก แล้ว กดลูกศรลง เพื่อไปหา th แล้วกด space bar อีกครั้ง
th_TH.UTF-8 UTF-8

เมื่อเลือกภาษาเสร็จ กดปุ่ม tab ตอนนี้ปุ่ม Ok จะถูกระบายสีแดง กดปุ่ม Enter

***หารายการโดยการใช้ปุ่มลูกศรขึ้นลง เลือกด้วยการกดปุ่ม Space bar เลื่อนเคอร์เซอร์มาที่คำว่า Ok ด้วยปุ่ม Tab
Default Language
เครื่องจะถาม Default language เลื่อนลูกศรลงไปหา en_US.UTF-8

เมื่อเคอร์เซอร์ มาอยู่ที่ en_US.UTF-8 กดปุ่ม tab

ตามด้วยปุ่ม Enter

เครื่องจะพาเรากลับมาที่ Terminal
[email protected]:~$ sudo dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LC_TERMINAL = "iTerm2",
LC_CTYPE = "UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Generating locales (this might take a while)...
en_US.UTF-8... done
th_TH.UTF-8... done
Generation complete.
[email protected]:~$
- sudo locale-gen “en_US.UTF-8”
sudo locale-gen "en_US.UTF-8"
[email protected]:~$ sudo locale-gen "en_US.UTF-8"
Generating locales (this might take a while)...
en_US.UTF-8... done
th_TH.UTF-8... done
Generation complete.
[email protected]:~$
หลังจากเสร็จทั้ง 3 ขั้นตอน ให้ลองเปิดไฟล์ locale ขึ้นมาดูครับ
nano /etc/default/locale

- กำหนด keymaps และ locale ด้วยคำสั่ง localectl
sudo localectl set-keymap us && sudo localectl set-locale LANG=en_US.utf8
- แก้ไขไฟล์ “/etc/environment”
sudo nano /etc/environment
เติมโค้ดนี้เข้าไปครับ
LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LANG=en_US.UTF-8
- รีสตาร์ทเครื่องครับ
sudo reboot
*** ถ้าใช้คำสั่ง sudo reboot แล้วเครื่องไม่กลับมาทำงาน ให้แก้ไขด้วยการ Reboot ที่ EC2 ครับ

ปัญหาอื่นๆ จากการสั่งอัพเดท และอัพเกรด Debian ไม่น่ามีอะไรแล้วครับ
เพิ่ม User
เราจะไม่ใช้บัญชี root ของ Debian ทำงานครับ แต่จะสร้างบัญชีใหม่ ในกลุ่ม sudo พิมพ์คำสั่ง
adduser <your-user-name>
ในที่นี้จะเป็น
sudo adduser manotlj
[email protected]:~$ adduser manotlj
bash: adduser: command not found
[email protected]:~$ sudo adduser manotlj
Adding user `manotlj' ...
Adding new group `manotlj' (1001) ...
Adding new user `manotlj' (1001) with group `manotlj' ...
Creating home directory `/home/manotlj' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for manotlj
Enter the new value, or press ENTER for the default
Full Name []: Manot Luijiu
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
[email protected]:~$
เพิ่มบัญชีผู้ใช้ใหม่เข้ากลุ่ม sudo
sudo usermod -aG sudo manotlj
ติดตั้ง ufw
sudo apt install ufw
[email protected]:~$ sudo apt install ufw
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
ufw
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 164 kB of archives.
After this operation, 852 kB of additional disk space will be used.
Get:1 http://cdn-aws.deb.debian.org/debian buster/main amd64 ufw all 0.36-1 [164 kB]
Fetched 164 kB in 0s (12.0 MB/s)
Preconfiguring packages ...
Selecting previously unselected package ufw.
(Reading database ... 26468 files and directories currently installed.)
Preparing to unpack .../archives/ufw_0.36-1_all.deb ...
Unpacking ufw (0.36-1) ...
Setting up ufw (0.36-1) ...
Creating config file /etc/ufw/before.rules with new version
Creating config file /etc/ufw/before6.rules with new version
Creating config file /etc/ufw/after.rules with new version
Creating config file /etc/ufw/after6.rules with new version
Created symlink /etc/systemd/system/multi-user.target.wants/ufw.service → /lib/systemd/system/ufw.service.
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for rsyslog (8.1901.0-1) ...
Processing triggers for systemd (241-7~deb10u8) ...
[email protected]:~$
UFW ได้ใส่รายชื่อโปรแกรมที่จำเป็นไว้ให้ตอนติดตั้ง สามารถขอดูด้วยคำสั่ง
sudo ufw app list
[email protected]:~$ sudo ufw app list
Available applications:
AIM
Bonjour
CIFS
DNS
Deluge
IMAP
IMAPS
IPP
KTorrent
Kerberos Admin
Kerberos Full
Kerberos KDC
Kerberos Password
LDAP
LDAPS
LPD
MSN
MSN SSL
Mail submission
NFS
OpenSSH
POP3
POP3S
PeopleNearby
SMTP
SSH
Socks
Telnet
Transmission
Transparent Proxy
VNC
WWW
WWW Cache
WWW Full
WWW Secure
XMPP
Yahoo
qBittorrent
svnserve
[email protected]:~$
เบื้องต้นนี้เปิดใช้แค่ OpenSSH ก่อนครับ ด้วยคำสั่ง
sudo ufw allow OpenSSH
[email protected]:~$ sudo ufw allow OpenSSH
Rules updated
Rules updated (v6)
[email protected]:~$
เพื่อให้ UFW ทำงานทุกครั้งหลังรีสตาร์ท Debian ใช้คำสั่ง
sudo ufw enable
สำหรับคำถาม Proceed with operation (y|n)? ให้ตอบ y ครับ
[email protected]:~$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
[email protected]:~$
ขอดูสถานะการทำงานของ UFW ได้ด้วยคำสั่ง
sudo ufw status
[email protected]:~$ sudo ufw status
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
[email protected]:~$
คัดลอกไฟล์ .ssh
หลังจากขั้นตอนนี้ เราจะล็อกอินเข้าใช้ Debian ด้วย ชื่อผู้ใช้ใหม่ เป็นส่วนใหญ่ ดังนั้นให้คัดลอกโฟลเดอร์ .ssh ให้กับผู้ใช้ใหม่ด้วยคำสั่ง
sudo cp -r ~/.ssh /home/<your-user-name>
ในที่นี้จะเป็น
sudo cp -r ~/.ssh /home/manotlj
[email protected]:~$ cp -r ~/.ssh /home/manotlj
cp: cannot create directory '/home/manotlj/.ssh': Permission denied
[email protected]:~$ sudo cp -r ~/.ssh /home/manotlj
[email protected]:~$
เมื่อคัดลอกโฟลเดอร์ไปแล้ว ก็เปลี่ยนชื่อเจ้าของ
sudo chown -R manotlj:manotlj /home/manotlj/.ssh
[email protected]:~$ chown -R manotlj:manotlj /home/manotlj/.ssh
chown: cannot read directory '/home/manotlj/.ssh': Permission denied
[email protected]:~$ sudo chown -R manotlj:manotlj /home/manotlj/.ssh
[email protected]:~$
ติดตั้ง Git
sudo apt install git
[email protected]:~$ sudo apt install git
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
git-man liberror-perl libgdbm-compat4 libperl5.28 patch perl perl-modules-5.28
Suggested packages:
git-daemon-run | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn ed diffutils-doc
perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libb-debug-perl liblocale-codes-perl
The following NEW packages will be installed:
git git-man liberror-perl libgdbm-compat4 libperl5.28 patch perl perl-modules-5.28
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 14.4 MB of archives.
After this operation, 85.2 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cdn-aws.deb.debian.org/debian buster/main amd64 perl-modules-5.28 all 5.28.1-6+deb10u1 [2,873 kB]
...
...
...
Setting up libgdbm-compat4:amd64 (1.18.1-4) ...
Setting up libperl5.28:amd64 (5.28.1-6+deb10u1) ...
Setting up git-man (1:2.20.1-2+deb10u3) ...
Setting up perl (5.28.1-6+deb10u1) ...
Setting up liberror-perl (0.17027-2) ...
Setting up git (1:2.20.1-2+deb10u3) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10) ...
[email protected]:~$
ZSH
sudo apt install zsh
[email protected]:~$ sudo apt install zsh
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
zsh-common
Suggested packages:
zsh-doc
The following NEW packages will be installed:
zsh zsh-common
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 4,685 kB of archives.
After this operation, 17.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cdn-aws.deb.debian.org/debian buster/main amd64 zsh-common all 5.7.1-1 [3,804 kB]
Get:2 http://cdn-aws.deb.debian.org/debian buster/main amd64 zsh amd64 5.7.1-1 [881 kB]
Fetched 4,685 kB in 0s (28.6 MB/s)
Selecting previously unselected package zsh-common.
(Reading database ... 26576 files and directories currently installed.)
Preparing to unpack .../zsh-common_5.7.1-1_all.deb ...
Unpacking zsh-common (5.7.1-1) ...
Selecting previously unselected package zsh.
Preparing to unpack .../archives/zsh_5.7.1-1_amd64.deb ...
Unpacking zsh (5.7.1-1) ...
Setting up zsh-common (5.7.1-1) ...
Setting up zsh (5.7.1-1) ...
Processing triggers for man-db (2.8.5-2) ...
[email protected]:~$
Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
[email protected]:~$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh...
Cloning into '/home/admin/.oh-my-zsh'...
remote: Enumerating objects: 1241, done.
remote: Counting objects: 100% (1241/1241), done.
remote: Compressing objects: 100% (1204/1204), done.
remote: Total 1241 (delta 20), reused 1103 (delta 15), pack-reused 0
Receiving objects: 100% (1241/1241), 867.00 KiB | 1.75 MiB/s, done.
Resolving deltas: 100% (20/20), done.
Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc.
Time to change your default shell to zsh:
Do you want to change your default shell to zsh? [Y/n] Y
Changing the shell...
Password:
chsh: PAM: Authentication failure
Error: chsh command unsuccessful. Change your default shell manually.
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!
Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugins, themes, and options.
• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord server: https://discord.gg/ohmyzsh
• Get stickers, shirts, coffee mugs and other swag: https://shop.planetargon.com/collections/oh-my-zsh
➜ ~
เนื่องจากการเปลี่ยน default shell จาก bash เป็น zsh ต้องระบุรหัสผ่าน การติดตั้งจึงไม่สมบูรณ์ เมื่อต้องการใช้งานให้พิมพ์คำสั่ง
zsh
Powerlevel10k
ตกแต่ง Terminal ให้สวยๆ ด้วย Powerlevel10k, ZSH Syntax Highlighting และ ZSH Auto Suggestions ให้พิมพ์คำสั่งต่อไปนี้ทีละคำสั่ง
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
➜ ~ git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
Cloning into '/home/admin/.oh-my-zsh/custom/themes/powerlevel10k'...
remote: Enumerating objects: 15252, done.
remote: Counting objects: 100% (341/341), done.
remote: Compressing objects: 100% (149/149), done.
remote: Total 15252 (delta 222), reused 258 (delta 192), pack-reused 14911
Receiving objects: 100% (15252/15252), 72.99 MiB | 14.73 MiB/s, done.
Resolving deltas: 100% (9860/9860), done.
➜ ~ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Cloning into '/home/admin/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting'...
remote: Enumerating objects: 6950, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 6950 (delta 13), reused 24 (delta 6), pack-reused 6913
Receiving objects: 100% (6950/6950), 1.49 MiB | 2.20 MiB/s, done.
Resolving deltas: 100% (4687/4687), done.
➜ ~ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Cloning into '/home/admin/.oh-my-zsh/custom/plugins/zsh-autosuggestions'...
remote: Enumerating objects: 2435, done.
remote: Counting objects: 100% (50/50), done.
remote: Compressing objects: 100% (42/42), done.
remote: Total 2435 (delta 21), reused 21 (delta 7), pack-reused 2385
Receiving objects: 100% (2435/2435), 566.38 KiB | 662.00 KiB/s, done.
Resolving deltas: 100% (1552/1552), done.
➜ ~
แก้ไขไฟล์ .zshrc
หลังจากติดตั้ง ZSH เราจะได้ไฟล์ .zshrc อยู่ที่ “/home/<user-name>” และถ้าต้องการใช้งาน Powerlevel10k พร้อมปลั๊กอินอื่นๆ เราต้องแก้ไขไฟล์ .zshrc 2 จุด คือ
- ZSH_THEME เปลี่ยนเป็น
ZSH_THEME="powerlevel10k/powerlevel10k"
- plugins เปลี่ยนเป็น
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
เสร็จแล้ว รีสตาร์ท ZSH ด้วยคำสั่ง
source ~/.zshrc
ทดสอบบัญชีผู้ใช้ใหม่
เปิดไฟล์ “~/.ssh/config” เพิ่มโค้ดนี้เข้าไปครับ
Host <Host-name> # ตั้งชื่อตามชอบ
HostName <Host-DNS>
User <new-user>
IdentityFile </path/to/private key/privateKey.pem>
ของผมจะเป็น
Host EC2-Tutorial-Debian-manotlj
HostName ec2-xx-xxx-xx5-50.ap-southeast-1.compute.amazonaws.com
User manotlj
IdentityFile /Users/manotlj/xxx/Keys/Node.pem
ให้ทดสอบบัญชีผู้ใช้ใหม่ด้วยการติดตั้ง ZSH, Oh My Zsh, Powerlevel10k, ZSH Syntax Highlighting และ ZSH Auto Suggestions
sudo apt install zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
เปิดไฟล์ .zshrc
sudo nano ~/.zshrc
แก้ไขบรรทัด ZSH_THEME ให้เป็น
ZSH_THEME="powerlevel10k/powerlevel10k"
และแก้ไข plugins ให้เป็น
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
ตกแต่ง Powerlevel10k
หลังจากติดตั้งให้แก้ไขไฟล์ .zshrc ให้เรียบร้อย แล้วตั้งค่า Powerlevel10k ด้วยคำสั่ง
source ~/.zshrc
// or
p10k configure
คำถามแรกคือ มองเห็นรูป สี่เหลี่ยม มั๊ย ตอบ y

คำถามที่สอง มองเห็น แม่กุญแจ มั๊ย ตอบ y

มองเห็นโลโก้ Debian มั๊ย ตอบ y

ไอคอนเบียดกันมั๊ย สำหรับบาง font มันจะเบียด บาง font ไม่เบียด ผมใช้ Anonymice Nerd Font บนเครื่อง Local มันจะเบียดกันหน่อย ผมตอบ n

Prompt Style ผมเลือก 2

Character Set ผมเลือก 1

Prompt Color เลือก 4

Show current time? เลือก 1

Prompt Separators เลือก 1

Heads เลือก 1

Tails เลือก 1

Height เลือก 2

Connection เลือก 1

Frame เลือก 1

Spacing เลือก 2

Icons เลือก 1

Flow เลือก 1

Enable Transient Prompt เลือก y

Instant Prompt Mode เลือก 2

แน่นอนครับเมื่อมีการแก้ไขค่า Configuration เราต้องสั่ง Save ให้ตอบ y

ตอนนี้ Terminal จะมีหน้าตาเปลี่ยนไป ตามรูป ครับ
