This post is an introduction only. After you've read it, please continue with your self-education. There's lots more to learn!
Accessing the NAS command-line-interface
QNAP NAS use a well-known shell called BASH (Bourne Again SHell).
SSH (Secure SHell) is a network service that is used to access a shell remotely. It's used to remote-access Unix, Linux and Mac computers (as well as Android, servers, routers, modems, etc...). It's also how you'll access your NAS command line. SSH requires an SSH server (daemon) to be running on the target device. Which is then accessed from one or more client shells.
A basic SSH server is already installed and configured in your NAS, but you'll need to check that it's enabled. Login to your NAS QTS desktop and navigate to Control Panel -> Network Services -> Telnet / SSH.
Ensure that the 'Allow SSH connection' box is ticked. Its default port is 22. Click the 'Apply' button if you made any changes. Done!
Login
Any terminal connection will require some information about the remote system that you want to connect to. It will need the IP address (or hostname) of your NAS and the username and password of a user who is permitted to access the NAS.
I'll skip locating your NAS IP address as this has been discussed extensively in the forums.
The SSH username will be 'admin' and the password will be the same password you use to login to the QTS desktop as the admin user.
Now, you just need a terminal program to remote-access the NAS. And that will depend on your operating-system:
- Windows
You'll need to install a terminal client to create an SSH connection. A common one for Windows is called PuTTY. After it's installed, you're ready to configure a connection to the NAS. Add your NAS 'admin' username and 'admin' password and NAS IP address.
For Windows 10 users with a build later than 1709, try the new Microsoft OpenSSH client. - macOS
You already have a terminal program installed! Read here for how to find and launch it.
Once you've launched 'Terminal', you are now at the command line. But it's on your local machine only. To connect to the NAS SSH service, type:... and enter your NAS 'admin' password when requestedCode: Select all
ssh admin@your-nas-ip
Hey, congratulations! You made it!
Now type 'exit' and get out of there.
The command prompt
Generally in BASH, you'll see two different characters as the command prompt: $ and #
$ is used to indicate that you're logged in as a regular user. This type of user is quite common on Linux desktop distributions. This account type can perform basic tasks, but nothing too dangerous. It's designed to be a nice, safe way to use Linux.
# is used to indicate that you're logged in as a superuser, or root user. This is more common on server or embedded distributions. This type of user has almost unrestricted access to the system and any commands that they run can cause a lot of damage.
The idea is that you use Linux as a regular user, only occasionally elevating your privileges to that of the superuser, through the use of sudo, or an equivalent, and only when needed.
The default SSH login for QNAP NAS is the 'admin' user. This is the root user. Which is why the command prompt is shown as #.
This means your commands can be quite dangerous. If anyone asks you to run a command as the root user, you should always ensure you understand what that command does, and consider the possibility that it can be destructive to your system. Google it if you have to. Over time, you'll get to know the good ones from the bad.
If you see a command-line example that shows the prompt as # or $, you don't need to type that character and the space that follows it. But everything after that should be entered as shown.
So, some example code might be shown as:
Code: Select all
[/etc/config] # uptime
Code: Select all
uptime
Linux files & the directory tree
Linux (unlike Windows) requires you to be case-specific when using commands and specifying filenames.
Which means myfile.txt is a completely different file to MyFile.txt, myFile.txt, myfile.TXT, and MYFILE.txt - even though they are all spelt the same. All of these files can exist in the same directory. The same applies to Linux commands and programs.
I tend to stick to using all lowercase names, as it means less keys to type. My own files are named like 'myfile.txt'
The Linux directory tree root is indicated with a forward slash: /
This means every absolute path starts with a forward slash.
If you ever see a path that does not start with a forward slash, it is a relative path. As in, it's relative to some other directory. This would usually be the directory you're currently in. It means that the path points to a sub-directory of your current directory.
On some Linux distributions, the command prompt is prefixed by your current path within the Linux directory tree and is shown surrounded by square brackets.
So, if your prompt looked like this:
... then you would be 'sitting' in the /etc/config directory. This is a good place to be if you need to process several files or sub-directories here.
Navigating the directory tree
In the QNAP NAS, the shares directory is found at: /share
All the standard and user-created shares can be seen here.
The 'Public' share is found at: /share/Public
If you're already in a sub-directory, and want to change into another sub-directory of that sub then you won't need to type the forward slash.
Examples:
- If I was already sitting in the /share directory (as shown by the start of the prompt between the square brackets), and then wanted to change into the Public sub-directory, I would use the cd command (change directory):
...and my prompt becomes:
Code: Select all
[/share] # cd Public
Code: Select all
[/share/Public] #
- If I wanted to go back up a level, I'd type:
...and my prompt becomes:
Code: Select all
[/share/Public] # cd ..
Code: Select all
[/share] #
- If I did this again:
...my prompt becomes:
Code: Select all
[/share] # cd ..
Code: Select all
[/] #
- Or I could do this faster by specifying the full (or absolute) path as / :
...and my prompt becomes:
Code: Select all
[/share/Public] # cd /
Code: Select all
[/] #
- If I was sitting really far down the directory tree and wanted to navigate back up to /share, I would specify the full (or absolute) path:
...and my prompt becomes:
Code: Select all
[/lev1/lev2/lev3/lev4/lev5/lev6] # cd /share
Code: Select all
[/share] #
- cat
This is the concatenation command. It is used to show the contents of text files. Multiple files can be specified.
Here, it's used to show the contents of the mdstat file located in the /proc/ directory:You'll encounter this particular command again-and-again on the forum. It's one of the first things to check when you have a RAID issue, or when you want to see the current state of your array.Code: Select all
cat /proc/mdstat
- ls
This is the 'list' command. It's used to list the contents of a directory. If you don't specify one, it lists the current directory.
There are some useful parameters that can be passed to it:This shows all files in a long directory list format. This is great for checking file and directory permissions and last-modified dates and times.Code: Select all
ls -la
But 'ls -la' has an alias. Type:... and you'll get the same thing.Code: Select all
ll
- rm
This is the 'remove' command. It's used to delete files (and optionally - directories). Please note: if you delete a file with this, there is no 'undo'. - mkdir
This is the 'make directory' command. It's used to create new directories. - rmdir
This is the 'remove directory' command. It's used to remove empty directories.
Some other commands
- df
Displays usage & free space for each of your mounts. - hostname
Displays the name of your NAS. - uptime
Displays how long the NAS has been running since bootup. It also displays the system load averages for the last 1 minute, 5 minutes & 15 minutes. - history
This shows the command-line history since the NAS was booted. The most recent command is shown at the bottom. You can re-run any of these by typing an exclamation-mark together with the line number of the command you want. E.g. typing '!765' then pushing 'enter' will re-run the command currently listed at line 765.
Tip: if you push the cursor-up (and cursor-down) key, you can quickly return to a previous command without showing this list. - which
Displays the path to the specified program - if it can be found in the current $PATH.
For example, if you type 'python', the default Python interpreter will launch:But if you want to know where the Python interpreter is run from, you would type 'which python':Code: Select all
[/share] # python Python 2.7.12 (default, Oct 31 2016, 15:57:24) [GCC 5.4.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Code: Select all
[/share] # which python /opt/bin/python