Ubuntu – 18.04 in local network as NAS/Headless

18.04networkingserver

At the moment, I just want to use my spare desktop as a storage space. I have a few doubts

  1. How to access the server machine over the WiFi network ? It has no monitor, mouse or keyboard connected to it. But has a WiFi adapter and runs 18.04.

  2. I would like to find some way to put and take files from the server. Mostly media files. And a few document files.

  3. The whole set up is meant for my main machine which is running out of space and runs 18.04. Once the file transfer is done, I need to find some way to shut down the server from the main machine.

Kindly help with these.

Edit :

I found the solution for 1 and 2. I now need to find out how to shut down the server PC from my main PC. Both Ubuntu 18.04. Thanks.

Best Answer

  • Let's say you have named your computers main and spare, where main is your main computer running out of space, and spare is your headless NAS.

    Step 1: Install openssh-server

    ssh stands for secure shell. It is one of the key means of controlling a headless server remotely. Open a terminal in the computer spare and use the command:

    sudo apt install openssh-server
    

    to install the ssh-server in your headless server computer.

    Step 2: Test ssh

    Now open a terminal in main and type the command:

    ssh username@spare.local
    

    where username is the username of the sudo user of the computer spare. If username in spare is identical to username in main, then you can ommit username@ and can just enter:

    ssh spare.local
    

    If ssh to spare.local does not work then try the local IP address instead:

    ssh username@192.168.x.y
    

    Your local IP address may look different. x and y are numbers.

    Answer the question about trusting the host and enter the sudo password for the spare computer. If all goes well you will be logged on to the computer spare while sitting at the computer main. You will know this by the change in the command prompt of the terminal from:

    YourUserName@main:~$
    

    to:

    YourUserName@spare:~$
    

    If you see this change in your terminal, congratulations! Now you can exit spare by typing exit. Your command prompt will return to:

    YourUserName@main:~$
    

    The test is complete.

    Step 3: Turn off spare

    Use the following command to turn off spare:

    ssh -t username@spare.local "sudo systemctl poweroff"
    

    This command sends the command inside the quotation marks to spare. Since that command starts with sudo you will be asked for your spare password twice, once for the ssh command, and the second time for the sudo to power off.

    Step 4: Write a script

    You can create a little script so that you don't have to type all that every time. The script can be called stopspare.sh and it can be saved in /home/$USER/bin folder of your main computer. The /home/$USER is your Home folder, $USER is your user name. If the bin folder does not exist in Home, create it.

    The script will have two lines:

    #!/bin/bash
    ssh -t username@spare.local "sudo systemctl poweroff"
    

    Remember to change username to the user name you use in spare. If you save the script in the location I suggested above, you can just open a terminal in main and type

    stopspare.sh
    

    to turn off the spare computer.

    Bonus!

    See the Ubuntu to Ubuntu section of this answer for how to use ssh based sftp in nautilus to access files in spare.

    You may also want to read How to harden an SSH server? for more about security of ssh server. Hope this helps

  • Related Question