Showing posts with label Ubuntu. Show all posts
How to SSH to a Virtualbox through NAT configuration. Using NAT as your Virtualbox network connection will create a private network connected to your host network. The only way to have direct access is to port forward any traffic to port 22 of your Virtual Machine. Please follow this step:
  1. Start your virtual machine and login
  2. Get the IP address by typing ifconfig
  3. Poweroff your machine
  4. Go to settings >> Network >> Advance >> Port Forwarding
  5. Add new port forwarding rule
    • Host IP : 127.0.0.1
    • Host Port: 2222
    • Guest IP: [IP of your virtual machine]
    • Guest Port: 22
You can watch the Video of this tutorial: How to SSH to a Virtualbox through NAT

Open your Terminal by pressing ctrl+alt+t

Copy this code and paste on the terminal

sudo apt-get update && sudo apt-get install rar unrar
Add User and Grant Root Privileges on Ubuntu. This tutorial we will learn how to Add user and grant root privileges so you could send command like a root user. Before starting, you should be logged as root user. Add a user
adduser demo
It will prompt you to enter the user details. Its optional. You can press [enter] till the last to skip Grant root privilege to demo user
visudo
Find the following code and paste the 3rd line
# User privilege specification
root ALL=(ALL:ALL) ALL
demo ALL=(ALL:ALL) ALL
Save the changes by pressing ctrl+o and exit ctrl+x You can now run command as root by using the command sudo following the command. Example :
sudo chmod 777 test_folder
sudo visudo
Create Ubuntu 14.04.4 server on Virtualbox. In this tutorial, you’ll learn how to install Ubuntu server in Virtualbox. It’s easy. You can do it yourself.
You’ll need:

Watch the video to preview how you should install the server:

Now lets get started. Install Virtualbox in your system and open it.
  • Click New
  • Name: MyDemoVM
  • Type: Linux
  • Version: Ubuntu (64bit)


  • On Memory Size, leave default and click next
  • On Hard disk, select Create a Virtual hard disk now and click create
  • Hard disk file type, select VDI and click next
  • Create Virtual Hard disk, select Dynamically allocated and click next
  • File location and size, leave default and click create

Select your VM MyDemoVM and click Settings
  • Click Storage >> Controller: IDE (Empty) >> Optical Drive >> Click the disk on the right
  • Locate your downloaded Ubuntu 14.04.4 server ISO file. This will mount the iso to the drive. Click Ok

Finally, start the new Virtual machine. It should boot to Ubuntu installation





  • Create your password
  • Use weak password? Just select Yes
  • Encrypt your home directory? Select No
  • Time Zone, select Yes
 
 
  • Partition Disks, just leave the default and select continue
  • Write the changes to disks? Select Yes
  • HTTP proxy information. Just leave blank and select continue
  • No automatic updates and press enter
  • On Software selection, just press enter
  • Install the GRUB boot loader on a hard disk, select Yes
  • Finish the installation, select Continue and VM will restart
  • Ubuntu console will load. Enter your username demo and password
Installing Ubuntu Server 14.04.4 online server . In this tutorial, you will learn how to install an online server by using Digital Ocean Virtual private server. This will also cover how to access the Ubuntu server using Putty with SSH configured.

Let’s get started

Register and configure the server

We will use virtual private server. The best service out there I found was Digital Ocean. For only $5 a month, you can have a private server. You will have a full control over it, install a multiple website as you like and many more.

Click this link to register and get $10 credit.
Once you’re logged, under the droplet page click Create Droplet
Under Distributions, find Ubuntu. Select the version 14.04.4 by click the arrow down. Its up to you whether you select x32(32bit) or x64 (64bit). I prefer x64


Choose a size : Select $5/mo. You can upgrade it later if you wish to.
Choose a datacenter region : Select the country closest to your place.
Add you SSH keys : If you have SSH key ready, press New SSH Key and paste you Public there. But if you don’t have idea about it, just leave it. In this tutorial, this section will not be covered. Instead we will install SSH key manually at the end of this tutorial.

Finalize and Create: Choose a hostname. Any name you prefer.
After the droplet is created, the credentials will be send to you email. It will be look like this
Droplet Name: test-droplet
Ip Address: 162.243.171.170
Username: root
Password: aebd02fcf3f39a73

Connecting to your newly created Ubuntu server

Open your Putty and paste the IP Address to the Host name textbox. On Saved Sessions, type MyDemoDroplet and click save.


Click open and a message will pop up, just click Yes.
Login as : root

Copy the password from you email and right click inside your Putty window. This will paste the password and finally press Enter.

Once successfully logged, you will be asked to change your password. Before that, you have to paste again your current password. If wrong current password is entered, Putty will close. If current password is accepted then, you can proceed to enter your new password.



if you wish to change the root password again just simply type sudo passwd root
 

Adding a User

To add a user, copy the below code and paste it in Putty. To paste it, simply right click inside the Putty window.
adduser demo

Give permission to the user
visudo

Find ‘# User privilege specification’. Below root add this line
demo    ALL=(ALL:ALL) ALL
Save it by pressing ctrl+o and exit press ctrl+x
Ensure you have access to the user (demo) directory
sudo chown -R demo /home/demo

Switch to demo user
su demo

Ensure you’re in demo root directory
cd

Create SSH directory
mkdir .ssh

Change permission
chmod 700 .ssh

Create a SSH file named authorized_keys
nano .ssh/authorized_keys
In this file, we will paste the SSH public key. But first we need to create SSH key

Creating SSH Key

Open Putty Key Generator and click Generate

Move your mouse around the window to generate the code. While doing this, the progress bar moves. The faster you move the faster it will finish.

Once finished, on key comment, you can add any word. Its optional. But it’s useful for you to identify this SSH key.

Protect your key by entering Key passphrase.
Click Save private key to your computer, also click Save Public key. Keep this file and never share it to anyone.

Copy the Public SSH key
On the big text box of the Key Generator, you will see long codes starting ssh-rsa …..This is the code we will copy. To do that, right click on that and click Select All. Now right click again and click copy.

Back to Putty again. Right click to it to paste the code. Save it by pressing ctrl+o and exit ctrl+x

Changing the ssh key permission:
chmod 600 .ssh/authorized_keys

Configuring Peagent

This will help you to login to your droplet automatically without asking password. Peagent will use your SSH key as authentication method to access your droplet. This is a secure way to access your server. So just a reminder, never share your SSH key file and your passphrase to anyone.

Run you Peagent software. You will see it in the bottom right of you computer near the clock. Right click it, click add key.

Locate the key where you saved your public key.
It will ask you to enter your passphrase.

*Please remember that auto-login will only work if your Peagent is running and SSH key is loaded.

Testing your SSH

Open your Putty, and select MyDemoDroplet Saved Session and click Load.
On the leftside (Category), find Connection and click Data.

On Auto-login username, type your username demo
Go back to session again (left, under Category) click Save and click Open
You should be seeing the image below. It means Peagent is working

You should be able to login to your server without entering a password

Disable the Root Access

We need to secure our server by disabling the root access. This will block root login to your server. It means you should login to your server using a user you created (demo). Don’t worry after disabling the root access. Once your user account is logged in, you can still switch to root account by typing su root
Lets disable the root access:
sudo nano /etc/ssh/sshd_config
Find the word ‘PermitRootLogin yes’, and change it to no
PermitRootLogin no

Restart SSH service
sudo service ssh restart

Congratulation, you have setup a new online Ubuntu virtual private server.
If you want to use the server to host multiple website, please follow my tutorial about Setup WordPress Multisite on Ubuntu 14.04 with Nigx
Desktop environment for Ubuntu 14.04 server This guide will tell you how to setup Desktop environment and a VNC server on an Ubuntu 14.04 server. The server will use a fast lightweight remote service – TightVNC package. After this, the next tutorial will explain how to connect to the server remotely and securely through SSH tunnel.
Prerequisites
  • Ubuntu 14.04 Server
  • Root Privilege

How to Install Desktop Environment and VNC server

First we have to get XFCE, TightVNC Packages. Do the following:
sudo apt-get update
sudo apt-get install xfce4 xfce4-goodies tightvncserver
In this tutorial, we will use demo as user. To add new user, do the following:
adduser demo
Giving permission to demo user:
visudo
Find the line # User privilege specification
Below the line root ALL=(ALL:ALL) ALL , paste the following line:
demo    ALL=(ALL:ALL) ALL
Save the changes by pressing ctrl+o and exit ctrl+x

Login to your user account that will be used to connect remotely.
su demo
Set VNC password
vncserver

Lets start configuring the VNC Server

vncserver -kill :1
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
nano ~/.vnc/xstartup
Insert this code:
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
Save it by pressing ctrl+o, then exit ctrl+x

Grant executable privilege:
sudo chmod +x ~/.vnc/xstartup
Create a VNC service file
sudo nano /etc/init.d/vncserver
Paste the following code. If you are using different user, please change the line 3.
#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="demo"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost"
. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;

stop)
log_action_begin_msg "Stopping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;

restart)
$0 stop
$0 start
;;
esac
exit 0
Save it by pressing ctrl+o, then exit ctrl+x

Now make this code executable:
sudo chmod +x /etc/init.d/vncserver
sudo service vncserver start
Every time you restart your server, you have to run sudo service vncserver start

Some may wish to always do this manually just to save server memory. You can start the vnc service only when needed.

But if you wish to run the service automatically, the step is mentioned in the next tutorial: Remote Ubuntu Desktop Environment using VNC Client

In the next tutorial, we will explain how to connect to the server remotely and securely through SSH tunnel.

Remote Ubuntu Desktop Environment using VNC Client through SSH tunnel. In this tutorial , you will learn how to remote your Ubuntu Desktop Environment using VNC Client through SSH tunnel. This is a continuation of the earlier post about setting up Desktop Environment for Ubuntu 14.04

This tutorial uses Windows computer. As the continuation of this tutorial, we will use demo username to login remotely to our server.
Prerequisite:
  • Putty software
  • VNC Client software

Setup your putty connection

We need to create SSH connection on your local computer

1. On Putty under host name, type the server ip address or domain name
2. Under Saved Sessions, type the name of this connection (any name, its up to you)
3. On the left panel, you see Category. Go to Connection >> Data >> Auto-login username >> type your username (demo)
4. On Connection >> SSH >> Tunnels>> Enter the following details


A. Source Port: 5901
B. Destination: localhost:5901
C. Click Add button
After adding this setting, you should see this on the listbox:
L5901 localhost:5901
Don’t click Open button yet or you’ll loose your setting.
5. On Category >> Session. On the right, click Save button
6. Then click Open to start the connection connect.
7. Login to your server by typing your password

Remote your Ubuntu 14.04 Server

Open your VNC client software. On VNC server text box, type localhost:5901


Click Connect button and enter your VNC Password
If you see below image, Congratulation!!! You just connected to your server.




In the previous tutorial, we mentioned every time we restart the server we should run sudo service vncserver start. This may give you an option to run the service only when needed just to save memory.
But if you wish to run the service automatically run the following code on your server console:
sudo update-rc.d vncserver defaults

Setting local Ubuntu VirtualBox VM t0 accept Putty connection. In this tutorial you will learn how to setup your local virtual machine (Virtualbox) so you can use putty to connect to your vitualbox.
Turn off your virtual machine.
On Virtualbox goto
Settings >> Network >> Adapter 1 (tab) >> Attached to:
Select : Bridge Adapter
Click Ok and run your Virtual Machine



On the Console, enter the command below to check your IP address:
ip addr show

#if you can see your local network address on the showed list, that’s a good sign
Change your IP Address:
sudo nano /etc/network/interfaces
Comment this line by adding # in the begining:
#iface eth0 inet dhcp
The following steps should be based on your network address. In this tutorial I will use my Network Address. My network maybe different from yours. If you have no idea about this, you may study a little about setting up network address.
Add the following lines
iface eth0 inet static
address 192.168.1.101
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
To save, press ctrl+o and exit ctrl+x
Reboot your VM:
reboot
Check your IP if it applied the setting we did:
ip addr show
If the IP is correct, start installing the SSH to your VM
sudo apt-get install openssh-server
You should be able to use Putty to connect to your Virtual Machine. Run your Putty and enter the following details:
  • Host Name: 192.168.1.101
  • Saved Sessions: MyDemoVM (any name)
  • Click Save and click Open

If you want to setup your Putty to login automatically, you should setup the SSH on your Virtual Machine. To do that, you may wish to read the following article:
SET SSH PUBLIC KEY AUTHENTICATION
Setup WordPress Multisite on Ubuntu 14.04.4 with Nigx. In this tutorial you will learn how to install wordpress with Nigx on Ubuntu 14.04.4 server with Multisite enabled.
What we need:
  • Ubuntu Server 14.04.4
  • Putty software
  • Root access
Tips: You can copy the code and paste it your Putty by simply right click your mouse inside the Putty window

Install and configure Nginx, MySql and PHP

apt-get update
apt-get install -y nginx mysql-server php5-fpm php5-mysql php5-curl php5-mcrypt php5-gd

You will be asked to enter password for SQL
Create folder where you will save WordPress files
mkdir /usr/share/nginx/wordpress

Remove symlink in the site-enabled directory
rm /etc/nginx/sites-enabled/default

Create virtual host file inside site-available
nano /etc/nginx/sites-available/mywp

Paste this code:
server {
listen [::]:80 ipv6only=off;
server_name example.com *.example.com myshop.com;

root /usr/share/nginx/wordpress;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ /index.php?$args ;
}

location ~ /favicon.ico {
access_log off;
log_not_found off;
}

location ~ \.php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}

access_log /var/log/nginx/$host-access.log;
error_log /var/log/nginx/wpms-error.log;
}

Save this file by pressing ctrl+o and exit ctrl+x
Create a symlink of this file inside site-enabled directory
ln -s /etc/nginx/sites-available/mywp /etc/nginx/sites-enabled/mywp

Test your Nginx configuration and restart
service nginx configtest
service nginx restart

Create your MySQL Database and add a WordPress User

Login to the MySQL command line
mysql -u root -p

Create a database. In this tutorial we will create new user – user: demo password: yourpassword and grant permission to the database
CREATE DATABASE wordpress;
CREATE USER 'demo'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'demo'@'localhost';
FLUSH PRIVILEGES;
exit

Installing WordPress

Download WordPress
wget http://wordpress.org/latest.tar.gz

Extract the file
tar -xf latest.tar.gz

Move the extracted files into Nginx directory
mv wordpress/* /usr/share/nginx/wordpress/

Assign ownership
chown -R www-data:www-data /usr/share/nginx/wordpress
Now go to your internet browser and open your website address (example.com).
You’ll be directed to a welcome page. Fill up the page and click Install WordPress

Select your language
Click Let’s go!

Here you need to enter you WordPress setup
Database Name: wordpress
Username: demo
Password: yourpassword
Database host: localhost
Table Prefix: wp_

**Click Submit button

Click Run the Install 



Enter the details of your website, you username and password that will be used to login to your WordPress


Click Install WordPress

Enable the WordPress Multi-site

This will allow you to have more than one website in a single WordPress. To make this happen, we have to enable the Multi-site function of the WordPress. Let’s start configuring the WordPress settings.
 
On your Putty again, type this:

nano /usr/share/nginx/wordpress/wp-config.php
 
Find this line “/* That’s all, stop editing! Happy blogging. */” at the bottom. Below this line, paste the following codes:

/* Multisite settings */
define( 'WP_ALLOW_MULTISITE', true );
#Save the file by pressing ctrl+o and exit ctrl+x


Go to your WordPress on browser and click Tools >> Network Setup. Please look at the picture below. We will copy these codes inside the blue box and green box and we will paste this in our server using Putty.



Now we need to go to Putty again and open the WordPress setting file

nano /usr/share/nginx/wordpress/wp-config.php
 
Find this line again (/* That’s all, stop editing! Happy blogging. */) Below this line we will paste the code from the web browser. Go back to you web browser and copy the codes inside the blue box (See picture above) and paste it to Putty.
Remember to change the SUBDOMAIN_INSTALL value to true



Save the file (ctrl+o) and exit (ctrl+x)
 
Next is to edit .htaccess

nano /usr/share/nginx/wordpress/.htaccess
On the web browser, copy the codes inside the green box shown in the picture below:


Paste it to you Putty. Save the .htaccess file (ctrl+o) and exit (ctrl+x)

Adding Domain Mapping Plugin manually

We have to download the plugin file and install it manually. On your Putty, enter this code one by one:

wget http://downloads.wordpress.org/plugin/wordpress-mu-domain-mapping.latest-stable.zip

apt-get install unzip

unzip wordpress-mu-domain-mapping.latest-stable.zip

mv wordpress-mu-domain-mapping /usr/share/nginx/wordpress/wp-content/plugins/

cp /usr/share/nginx/wordpress/wp-content/plugins/wordpress-mu-domain-mapping/sunrise.php /usr/share/nginx/wordpress/wp-content/
 
Let’s edit the WordPress configuration again:

nano /usr/share/nginx/wordpress/wp-config.php
 
Find /* That’s all, stop editing! Happy blogging. */ and below this line, add the following code:

define('SUNRISE', 'on');
 
ACTIVATING THE PLUGINS
On your web browser, click the My Sites >> Network Admin >> Plugins


Find WordPress MU Domain Mapping and click Network Activate


Go to Settings >> Domain Mapping and make changes to the Domain Options:


On you Putty

mkdir /usr/share/nginx/wordpress/wp-content/mu-plugins
nano /usr/share/nginx/wordpress/wp-content/mu-plugins/wpms_blogid.php
 
Paste this code:

<?php
add_filter( 'wpmu_blogs_columns', 'do_get_id' );
add_action( 'manage_sites_custom_column', 'do_add_columns', 10, 2 );
add_action( 'manage_blogs_custom_column', 'do_add_columns', 10, 2 );

function do_add_columns( $column_name, $blog_id ) {
if ( 'blog_id' === $column_name )
echo $blog_id;
return $column_name;
}

function do_get_id( $columns ) {
$columns['blog_id'] = 'ID';
return $columns;
}
 
Save the file (ctrl+o) and exit (ctrl+x)
Congratulation, you have a WordPress Multi-site


Ubuntu: Delete (remove) a user on Linux Ubuntu server. Before starting to this tutorial, you should be on root user first. Now do the following command:
userdel demo
Or if you want to remove the user files then use command:
userdel -r demo
If the user has root privileges, you may wish to remove it.
visudo
Find the following code
# User privilege specification
root ALL=(ALL:ALL) ALL
demo ALL=(ALL:ALL) ALL
Remove the 3rd line. You should see only root:
# User privilege specification
root ALL=(ALL:ALL) ALL
Save the changes by pressing ctrl+o and exit ctrl+x
Copyright © 2012 My Linux Code