3. Topics I will cover
Creating a VPS (droplet) on Digitalocean.
Creating a new user with root privileges.
Setting up ssh.
Setting up a basic firewall.
4. Prerequisite
Access to an ubuntu 16.04 VPS.
OpenSSH for Linux of Mac.
An ssh client for windows (PuTTY / gitbash)
6. Create a VPS
On digitalocean, VPS is called droplet.
Digital ocean’s interface is clean and beginner friendly.
To get 10$ beginner credit sign up with this referral link:
https://m.do.co/c/0dc352a7f06c
7. Log into the Droplet with root
By this time digitalocean has emailed the login credential.
Open a terminal and log in with this command and enter the emailed password:
ssh root@your_server_ip
We will be prompted to change the password.
8. Create a New user
root is the administrateive user. It has privileges to cause destructive changes
to our server.
We will create a new user with the following command:
adduser azam
Give it a ‘superuser’ or administrative privileges:
usermod -aG sudo azam
9. Generate an SSH key
SSH is a network protocol which is used to establish secure connection to
remote machine over the internet and run commands.
To generate an ssh key open a local terminal (ie: another git bash) and enter this
command:
ssh-keygen
Print the public key with the following command:
cat ~/.ssh/id_rsa.pub
Select and copy.
10. Copy the public key in the Droplet
On the remote terminal we will temporarily switch to the new user:
su - azam
Create an .ssh directory and restrict permission:
mkdir ~/.ssh
chmod 700 ~/.ssh
Open a file in .ssh named authorized_keys:
nano ~/.ssh/authorized_keys
Now paste the copied public key, hit ctrl+x and press y.
Restrict the permission of the authorized_keys:
chmod 600 ~/.ssh/authorized_keys
11. Disable Password Authentication
As a root user open the ssh daemon configuration:
sudo nano /etc/ssh/sshd_config
Find the line that has PasswordAuthentication and change its value to no:
PasswordAuthentication no
To save hit ctrl+x and press y.
Enter this to reload the ssh daemon:
sudo service sshd reload
12. Test Login
Do not exit the first remote terminal until we are certain that everything is
working fine.
Open a new terminal and log into the droplet with the new credential:
ssh azam@your_server_ip
If you need root privileges just type sudo before the command:
sudo some_command
13. Set Up Basic Firewall
On ubuntu 16.04 server we can use UFW - uncomplicated firewall.
Applications can register their profile with UFW.
To see the available application profiles:
sudo ufw app list
To allow SSH connection run:
sudo ufw allow OpenSSH
Enable the firewall by typing:
sudo ufw enable
Check ssh connection are allowed:
Editor's Notes
আপনি আপনার এপ্লিকেশন হোস্ট করার জন্য একটি নতুন সার্ভার বা ভিপিএস নিয়েছেন। কিন্তু এটিকে স্টেবল ও নিরাপদ কিভাবে করবেন? নতুন সার্ভার নেয়ার পর কি কি করা দরকার?
আমি মুহাম্মদ আরাফাত আজম। আমি আজকে আপনাদেরকে দেখাব কিভাবে একটি নতুন সার্ভার সেটআপ করতে হয়।
আমি আজকে যা যা দেখাব সেগুলো হল -
ডিজিটাল অশানে একটি নতুন সার্ভার তইরি করা
রুট প্রিভিলেজ সহ একটি নতুন ইউসার একাউন্ট তইরি করা।
সিকিউর শেল বা এসএস এইচ সেট করা।
বেসিক ফায়ার ওয়াল সেটআপ
টিউটোরিয়াল অনুসরণ করতে হলে আপনার যা যা লাগবে সেগুলো হলও
একটা উবুন্টু ১৬।০৪ ভিপিএস
লিনাক্স বা ম্যক ব্যবহার কারি হলে ওপেন এস এস এইচ
আর উইন্ডোজে একটি এস এস এইচ ক্লায়েন্ট
উইন্ডোজে এস এস এইচ ক্লায়েন্ট গিতব্যশ ইন্সটল করার জন্য এই লিঙ্কটি অনুসরণ করুন। গিটের লেতেস্ত ভার্শন নামিয়ে ইন্সটল করুন। আপনি চাইলে পুতিও ব্যবহার করতে পারবেন।
এই টিউটোরিয়ালের জন্য আমি ডিজিটাল অশানের ভিপিএস ব্যবহার করব। ডিজিটাল অশান একটি ক্লাউদ ইনফ্রাস্তাকচার প্রভাইদার।
ডিজিটাল অশানে ভিপিএস্কে ড্রপ্লেট বলে।
এর ইন্টারফেস অনেক পরিচ্ছন্ন এবং বিগিনার ফ্রেন্ডলি।
আপনি যদি এই রেফারেল লিঙ্কটি অনুসরণ করে সাইন আপ করেন তবে দশ ডলার রেফারেল বোনাস পাবেন যা দিয়ে ৫১২ মেগা মেমরির ড্রপ্লেট দুমাস ব্যবহার করতে পারবেন।
ড্রপলেট তইরি হয়ে গেলে একটা এমেইলে লগইন ক্রেদেনশিয়াল দিয়ে দেয়া হবে।
প্রদত্ত পাসওয়ার্ড আমরা একবার ব্যবহার করতে পারব।
একটা টার্মিনাল ওপেন করে আমরা ssh কমান্ড দিয়ে আমাদের ড্রপ্লেটে লগইন করব।
নতুন পাসওয়ার্ড দিতে প্রম্পট করলে আমরা পাসওয়ার্ড পরিবর্তন করব।
রুট হচ্ছে এদ্মিনিস্ত্রেতিভ ইউজার। রুট ইউজারের সব রকমের এক্কেস আমাদের সার্ভারে আছে। ফলে রুট দিয়ে কাজ করতে গিয়ে ভুল করে ফেললে সেটা বিপদজনক হতে পারে।
এই কারণে আমরা একটা নতুন ইউজার তইরি করব।
তারপর সেটাকে সুডো প্রিজিলেজ দিব।
সিকিউর শেল বা এসএস এইচ একটি নেটওয়ার্ক প্রোটকল। এই প্রোটকল দিয়ে সার্ভার এডমিনরা বা সফটওয়ার ইঞ্জিনিয়ার রা নিজেদের কম্পিউটার থেকে রিমোট মেশিনে বা সার্ভারে নিরাপদে কমান্ড চালাতে পারে।
আমরা একটা নতুন টার্মিনাল খুলে এস এস এইচ কি জেনারেট করব
এরপর পাবলিক কি টা টার্মিনালে প্রিন্ট করে সেটা কপি করব।
এই কি ব্যবহার করে আমরা আমাদের দ্রপ্লেতে লগইন করব।
আমরা আমাদের প্রথম টার্মিনাল থেকে, যেটাতে আমরা আমাদের ভিপিএসে লগইন আছি সেখানে, নতুন ইউজার একাউন্টে সুইচ করব।
হোম ডিরেক্টরিতে .ssh ডিরেক্টরি তইরি করব।
সেখানে অথরাইজড কিস ফাইলে কপি করা পাবলিক কি টা যুক্ত করে দিব।
এরপর আবার রুট ইউজারে সুইচ করব।
যাতে এসএস এইচ কি ছাড়া লগইন না করা যায় সেজন্য পাসওয়ার্ড অথেনটিকেশন বন্ধ করে দিতে হবে।
আমরা ssh daemon এর কনফিগারেশন ফাইলটি এডিট করব
পাসওয়ার্ড অথেনটিকেশন বন্ধ করে দিব
এবং সবশেশ এস এস এইচ দেমন রিলোড করব।
আমরা যেহেতু পাসওয়ার্ড অথেক্তিকেশন বন্ধ করে দিয়েছি, এজন্য সব ঠিকমত কাজ করছে এটি নিশ্চিত করার আগে রিমোট টার্মিনাল থেকে এক্সিট করবনা।
একটা নতুন টার্মিনাল খুলব এবং নতুন তইরি করা ইউজার দিয়ে লগইন করার চেষ্টা করব।
রুট প্রিভিলেজ দিয়ে কোন কমান্ড চালাতে হলে শুরুতে sudo দিতে হবে।
উবুন্টু সার্ভারে আমরা ufw বা uncomplicated firewall দিয়ে কোন কোন সার্ভিস এক্কেস করা যাবে সেটা নিয়ন্ত্রণ করতে পারি।
প্রতিটি এপ্লিকেশন ইন্সটল হবার সময় নিজ নিজ প্রোফাইল UFW তে রেজিস্টার করে।
আমরা এভেইলেবল এপ্লিকেশন প্রোফাইল চেক করব
এস এস এইচ সার্ভিসকে আলাও করব
এরপর ufw এনাবল করব
সবশেষে দেখব কোন কোন সার্ভিস এলাও করা আছে।
পরবর্তীতে আমরা যদি ওয়েব সার্ভার যেমন এঞ্জিনেক্স ইন্সটল করি সেটাও ufw তে এলাও করতে হবে
আমরা দেখলাম আমরা কিভাবে একটা ভিপিএস এ নতুন ইউজার তইরি করে এসএস এইচ এক্কেস দিতে পারি। এবং uncomplicated firewall দিয়ে আমাদের সার্ভার সুরক্ষিত করতে পারি। এই ভিডিওর প্রেসেন্টেশনের লিঙ্ক ভিডিওর ডেসক্রিপশনে দেয়া আছে। জাজাকাল্লাহ খাইরান।