I found a nice PHP script for Wake on LAN. I loaded it on the Raspberry Pi that I have and configured it for my system. The Raspberry Pi runs 24/7, so I can just navigate to a web page that it serves, hit a button and start up one of my machines at home from anywhere. Mostly this is useful for the starting my Linux file server remotely but I do use it to fire off the desktop too.
Right from the read me file for the code…
REMOTE WAKE/SLEEP-ON-LAN SERVER
=========================
This is simple webapp that runs on your Raspberry Pi to turn it into a remotely accessible Wake/Sleep-On-LAN Server. [Follow the detailed tutorial](http://www.jeremyblum.com/2013/07/14/rpi-wol-server/) on my website for instructions on how to get this working, and forwarded through a router. This is very useful when you have high-powered machine that you don’t want to keep on all the time, but that you want to keep remotely accessible for Remote Desktop, SSH, FTP, etc.
It is rare when something works right out of the box. But, this did, I followed Jeremy Blum’s instructions and within a few minutes I had this working. It has a nice drop-down menu where you can select a computer. It pings it to see if it is awake, then you can wake it from anywhere in the world. Once the WOL packet is sent, the application keeps pinging the PC at a defined interval and you can see when it wakes. I have not tried the sleep functionality as I am using it with Linux PC’s and his outline covers Windows machines. I am sure the code could me modified to shut down a Linux PC somehow. Perhaps it automatically SSH’s in and sends a shutdown command, something like that. I have my Linux server set to shutdown automatically so I don’t need this functionality myself.
It is configurable through an easily understood config.php file as well. You can set the computers name and IP address, MAC address, timing between pings, amount of times to ping the machine and etc.
One server I have is fairly low on resources, so I opted not to run FTP. It would just mean yet another service that would have to run on a low RAM unit. So to move files to and from this server I use scp or sftp from Linux and WinSCP from Windows.
SCP Example
These examples assumes you can SSH into your server!
Using a FQDN
The following example shows downloading a directories content from a remote server using a fully qualified domain name.
Example of uploading a single file to a remote server from the home directory of the user to a specific location under the users home directory tree on a remote computer, note the tilde (~) means home directory of user.
To connect using sftp, a ftp tunnel using SSH, typically you can use the “Connect to Server” found for instance in Ubuntu under Places.
Set connection type to SSH
Set the server
IP address or FQDN
Port is set to 22, the standard SSH port
Folder is set to any folder that the user has permission to get into, /home/user is a safe bet.
Username is set
You can add a bookmark to keep getting in to this connection
It will ask for your login password upon connecting
SFTP via Browser
Also from a Firefox browser, Haven’t tried this on others! you can simply put sftp://user@serveraddress in the address bar. This will connect you to your home folder after you give the password at the prompt. I noticed that in Ubuntu, it will do the same thing that the “Connect to Server” option will do. It will show a folder on the desktop
after connecting with the browser that it the sftp connection
WinSCP
From Windows I have used the tool WinSCP for years as it supports FTP, SFTP and SCP. http://winscp.net/eng/index.php
It also loads support, by editing the registry perhaps for using the sftp:// type of connection via Windows Explorer.
rsync
For Linux there is also the command rsync, remotely synchronize directories. I haven’t used this but once or twice so I don’t have much to say about it yet.
One more comment on SSH. Typically I leave SSH (Port 22) closed and open it up only when needed on this server. I do this by remotely logging into a my router and opening it and closing it. Alternatively you could configure a firewall to only allow certain IP numbers a connection to SSH and denying all others. This can be done using the direct method of editing the iptables ( I will write more on this, TBD) or using a tool such as UFW or the graphical version of it called GUFW to handle this.
At this point, I get off of the server, I mean disconnect the monitor and keyboard. But first remember to configure the BIOS to ignore keyboard errors, important for unattended operation! I wait until at least the updates are done and I have tested out the static IP to “unhook”. If you are setting up firewalls it is best to do it sitting at the machine as well. Because a mistake setting up the firewall can lock you out of connecting with SSH remotely! The firewall, set via the iptables, can block or allow access to incoming or outgoing ports, by passing or dropping packets. The firewall can be configured via tools such as ufw (uncomplicated firewall) to allow certain services to go through. IP addresses and ranges can be blocked or allowed as well. This can get complicated in a hurry. More on this later.
Logging onto the machine remotely from Linux, is done at the command prompt using either of these…
ssh machines-name
ssh machines-ip-address
From Windows, fire up Putty and put in the machines-name or machines-ip-address in the appropriate spot. You will be presented with a CLI ( Command Line Interface ) prompting for password on connection.
If the machines-name one doesn’t work, then the name is not mapping to the IP address locally, it is a DNS thing in this case. You can just go ahead and use the machines IP. Which you should have configured static previously.
With both Win and Linux you will get a warming the first time you SSH into the server. The warning has to do with not trusting the RSA key, which makes sense, giving that it is the first time the connection is being made. The machines don’t know each other, so just enter yes and they will be key-paired so that in the future you won’t be presented with this question.
With SSH you can continue with the configuration of the machine remotely. The next item on the list is Samba. If you are configuring remotely at a Windows machine it is easy to see if you are configuring Samba correctly. It can be tricky to get working. Searching on line, I found a lot of posts on folks struggling to get Samba to work.
Getting it to the outside world
So far all of this operation has occurred on the LAN. What if you want to make a website or any other port connected to the outside world.
For me, I went into my router via its web config page and opened up port 80 to the outside word, by forwarding the port, connecting the forwarded port to the local IP address of the server. Along with the Port 22 for SSH as well. If you run Webmin you can forward port 10000 for Webmin. Now I could navigate to my external IP and see the web page of the web server from anywhere. Initially I made port 8080 available so that I could login to the router as well, but then I decided against it. I figure why open more ports than you need. Keep it simple. How many times will I need to actually get to the router, it’s mostly set it and forget it. The inexpensive Netgear N150 router has worked reliably and has near perfect up-time so far.
Noip for a Static Address
Install noip2. Not sure, my notes aren’t clear but, I think I had to compile and install it after it didn’t work via sudo apt-get install noip2. This is dynamic DNS support support for the URL. The noip2 program runs at startup and periodically reports the IP address of my ISP to the noip headquarters, I suppose, so the URL I picked out goes to my server. Otherwise I would have to go to the actually IP address and then find out what it is when it changes. This seems like a pain if you have to do it remotely, even while experimenting initially. Luckily my ISP does not change my address very often so this step for me is optional. I did run noip with my last server. I may run it for this one at some point. But the IP address stays the same for months so it is not a pain, even if I wanted to point to it with a name. I could even so something clever like send myself an email when it changes.
Router support for noip or dyn-DNS
A new firmware upgrade for my router has added support for noip, so now it would be possible to do this from the router itself. I haven’t investigated yet, but check yours it may be possible to use noip or dyn-DNS right from the router end and not have to mess with the server at all.
Beware of opening ports
Having things like SSH and FTP, ports 22 and 21 respectively open to the outside world can invite trouble. My router logs routinely show attempts to access the SSH port by various IP’s, if I leave them open, which trace to foreign countries, China mostly. I don’t leave FTP open at all and am keeping SSH off as well until I can firewall this server. For now accessing SSH and FTP from the LAN is good enough. Ideally I want to modify iptables to only allow trusted IP addresses into SSH, the rest, drop the packets as they arrive.
These attempts I see in the router log probably try to hit the username and password with a bunch of guesses or try to look for obvious ones. These cyber-criminals are trying to jack into your machine and do whatever damage they can to the web. So be cautious.
Next do some file sharing with Windows machines using Samba…
This is meant to be an outline not a complete guideline. It is based off on notes I took and may be helpful to keep me or someone else straight on the process in the future. There are some sections that are a bit light, but there is more out there on the web and half the problem for me at least is remembering this kind of outline. If I have the outline, I can jump off and find more. This particular post on the install is rather long, but it didn’t seem like a good idea to break it up.
Install, using Ubuntu Server 12.04
Boot via the DVD that was created by burning the downloaded ISO to it.
Select Install Ubuntu Server, unless of course you want to test out RAM, a good idea if it has been freshly installed. Which was true in my case. So I ran MEMTEST overnight via this menu first.
Next you will be presented with screens to select language, location and keyboard type.
If you know what kind of keyboard you have select no to the next screen. If not selecting yes will put the keyboard through a test, having you press various keys to identify it.
Next the Ubuntu Server install will start loading additional components, this can take a few minutes…
Networking Setup
Ubuntu Server will automatically configure DHCP. Later on, after the install, this will be switched to a static IP address.
Create a hostname for the computer. Choose something that makes sense for you. A really long hostname ( I think > 14 chars) can present issues with Windows when using Samba. It will truncate the name, just something to be aware of.
User and Password
You can set up a user next by filling out a username and password. After the installation you can add more users if you need to.
The first screen will ask for your name, this could be your real name.
Next you will enter your username. Something simple like your first name in all caps is a good choice.
Choose a decent password. Something not listed in a dictionary is a good choice, with some numbers and a capitalized letter, punctuation as well. One approach taken is to take two unrelated words that are easy to remember and concatenating them. Whatever you do, don’t lose it, I am not sure you can recover it unless you can reset it as root, provided you have that password. In Ubuntu, you have to log in as a user to even execute sudo. So if you have one user and lose the password, it’s probably game over.
To encrypt or not to encrypt your home directory on your Ubuntu Server install. I chose no, it’s a server, I am not going to do much with the home directory. Encryption is nice, but it comes with a small speed cost of decoding, this could be a burden on a slow processor.
Time Zone
Where are you in the world? I think the install is taking an educated guess as to where you are, so what it chooses may be correct, just double check. If not, set up your time zone via this drop down menu. After the install it is possible to install ntp which can keep the server clock sync’ed up with an atomic clock time.
Partitioning
Whole disk, LVM. Lots of options. I choose to wipe the disk clean and use LVM. I will be adding disks to this machine and with LVM, they can appear as one big disk, not mounting required. LVM is a thin layer of software that manages the Logical Volumes. Therefor it does consume a small amount of resources and must lower disk transfers slightly. One thing that I did noticed once with an LVM disk, is that I could not read it using a IDE to USB adapter. It was invisible to it. I have to try plugging that disk into a Linux machine at some point to see if I can read it’s contents. So it seems that LVM could complicate a recovery of a disk. Supposedly an advantage of LVM is that you can mirror copy the volumes and expand them across disk. I need to research this some more as it is new to me.
If you have more than one disk, you have to choose which one the OS will install to.
At this point in the install, I ran into an issue with the fact that the disk I was trying to use was originally used in another Linux machine with 3 disks used in LVM. Nothing I did seemed to work as it gave me a warning about the disk being a part of a 3 disk LVM set. I stopped the install and used a CD that came with a drive I bought years ago and wiped out the drive. Then I did the reinstall and successfully made it to the following confirmation screen. If all looks well you can hit Yes, if not hitting No will allow you to work backwards. Hitting Yes is final as disk writes will occur.
System Install, Configuring Updates and Installing Software
Once the partition in complete the OS will install, which will take several minutes.
There is an option to have automatic updates, this is a good idea, especially for a headless server. So it can take care of itself with a minimum of fuss.
Choose software to install. Open SSH is a must if you are to remotely shell into the server. Because I will be running OwnCloud on this unit and it uses a web interface and a database and PHP, installing LAMP Server is a must. I will also make a few folders that can be reached directly from Windows computers on the network, mostly for direct backups, so Samba file server is a must.
Final Steps for Ubuntu Server 12.04 install
The Ubuntu server install will prompt for installation of software. Install the following when prompted by the screen.
Open SSH
LAMP
Samba Server
MySql Password
Because the LAMP Server (Linux-Apache-MySql-PHP) installs MySql a password is needed for the “root” user of the database. During the process of configuring LAMP, a prompt will appear for a MySQL root password, make it something memorable in case you ever have to manage or do work with the database manually, or if a program asks for it, such as when doing a WordPress install.
GRUB
As the description for GRUB states this is the only install going in, so it safe to hit Yes and go ahead. Results may vary for you specific case. If you have a multi boot machine, GRUB will setup Ubuntu Server to load first, if you are configuring a multi boot machine.
The done screen, pull out the disk hit continue and the PC now will reboot, I went into the BIOS and did a few more things to it.
Additional Steps in the BIOS
All BIOS are a bit different. Yours may not look the same, but should have similar settings. This is a Dell Dimension 2400. Configure the BIOS to ignore keyboard errors “Do Not Report”, important for unattended operation with a keyboard and monitor!
I also set “Remote Wake Up” to On as I will use Wake On LAN to wake this machine up remotely. I cover it here … Wake On LAN via Ubuntu Linux
I will set Suspend Mode to S3. This has worked well for me with Dell machines in the past. I am considering writing a CRON script that will suspend to RAM when the server is idle for a period of time, so setting this to what I want it to be now is a good idea.
If the power goes out and comes back on I want the server to go back to what ever state it was in, if off stay off, if it was on, restart. I have used this in the past and it does work well.
Final Steps for Install when the machine reboots
When you exit the BIOS, you be prompted for your username and password.
For good measure run the update and upgrade commands, if all is well they should complete without error.
sudo apt-get update
sudo apt-get upgrade
One of the first steps when configuring a server post-install is to set up a static IP address.
I had an old NEC P3-500 computer from 2000 set up as a server. It ran Lubuntu 13.10. SSH, vsFTP, LAMP stack, Webmin, Samba, code for remote desktopping and a WordPress install.
I used it to test out things, I learned a lot about WordPress in a short span of time on it. Plus I had it running two web cams and placing time lapse frames on line. I was using the cams to monitor indoor temperatures when I was away from home in the winter. It was a good test bed, but quit in late March. No video, no booting, I decided not to troubleshoot, it was old and worked long enough. It still had the original 8gb HD, which started with Win98 then XP, the Ubuntu 9.10, then Lubuntu, good life span for a drive.
A few months ago I came across a Dell Dimension 2400 at no cost. Higher performance than the NEC. So I will go with that as the replacement. The idea is to load Ubuntu Server on it, no need for a desktop, I realized. I am comfortable enough with the Linux command line, been using it since 1997, to go without a “desktop”. In the meantime since the last server, I discovered ownCloud
OwnCloud
OwnCloud will let me set up a personal cloud, limited only by hard-drive space. I have not used it much yet, but it would be good for storage of photos and music, plus contacts, bookmark and calendar sync. It seems promising. I am reading the user manual and administrator manual. Two of the features that I am interested in are, making a photo gallery in it and being able to store music files and streaming them. Then I could have my personal “internet radio” station and listen to the music that I want to on any device, in theory, anywhere.
Samba
I finally got Samba working, which allows the Linux computer to interface correctly with Windows as far as file sharing. Now I can create a network folder on the Linux server to access with a Windows computer, which will be good for backups. It can be treated like another hard drive and files can be transferred easily. It was a lot of work, one small mistake that I made in providing a name was the problem. Windows did not like the use of special characters, slashes like / or \ in the name of the folder! It kept telling me, I don’t have permission for the folder and that the path did not exist. I thought I was being smart naming the network folder the same as it appears on the server computer, /files/erick, that was a big mistake! I went crazy checking the firewall, checking the DNS names & addresses. Reading things online. Then I added a new folder with a simple name, just files, and it worked, so I changed all of the folder names to something simple and it worked fine! I will use the Samba shares mounted as drives, for backup of the Windows computers, in one location.
I did learn a useful command in the process of troubleshooting, running…
smbclient -l //serveripaddress -u username
from the server CL lets you see all of the computers on the workgroup to make sure they show up and names are being resolved. If they look OK then you know you have that part working alright. As far as the firewall, it is off by default when Ubuntu Server installs. This can be confirmed by a dump of the iptables.
And of course, I installed the server with the SSH option turned on. So I can do all of this without having to be in front of the machine.
IP is set to static too. I learned that you can now set the DNS servers in the same config file as setting up static IP.