In the past, I have shown you how to connect to your VPS over SSH on both Windows and Linux. But if you are a first-timer and you have never used a VPS before, you may be quite lost once you’re on your server. In this tutorial, I want to show you some basic commands for moving around your first ever (Linux-based) VPS.
I am going to assume a Debian-based distribution in my examples. I’m using Ubuntu 14.04 more specifically. Most commands should work on any Linux distribution; the only distribution-specific commands are those for the package manager.
Ready? Set? Let’s go!
ls
The first command I want you to know about is ‘ls’. ‘ls’ is used to list directory contents, so it lists the files and directories contained in the the directory you currently are in. When you log in via SSH, you end up in your username’s home directory. In case of root, this is /root. In case of a regular user, it is usually /home/{username}. To use ‘ls’ just type:
ls
In the terminal and you should get a list of files and directories contained in the current directory.
‘ls’ has three options/arguments that are most commonly used: ‘-l’, ‘-a’, and a path name. I’ll briefly go over all three of them:
- If you pass ‘-a’ to ‘ls’ you get the following command: ‘ls -a’. This ensures that hidden files and directories (whose name starts with a dot . ) are also shown.
- If you pass ‘-l’ to ‘ls’ you get the following command: ‘ls -l’. This shows the results as a list with more details, rather than a columned view.
- If you pass a path (like /var/www) to ‘ls’, you get to see the contents of that directory. For example, ‘ls /var/www’ shows you the contents of the directory /var/www. This also works individual files.
You can combine options starting with a minus ‘-‘ by stacking the characters. So ‘ls -a’ and ‘ls -l’ combined would become ‘ls -al’ and it will both show hidden files and directories and show them as a list.
cd
The ‘cd’ command helps you move around. By typing ‘cd’ followed by a path, you change the current directory to that path. For example, if you want to go to /var/www, you would type:
cd /var/www
Typing ‘cd’ without any arguments returns you to your username’s home directory.
Tab completion
When typing commands, arguments, or path names, you can often tap the tab key to get the command or path completed. When there is more than one option, your shell shows a list of options available. The only way to really get the hang of this is by trying it out.
nano
Nano is a tool for viewing and editing text files; it does not work with binary files like images or zip files. When you want to open a file, say /etc/apt.sources.list, you type the following command:
nano /etc/apt.sources.list
This opens the nano editor where you can freely move around using the arrow keys and type wherever you want.
Nano offers various options on the bottom of the screen. All options start with a ^, which means you should use the CTRL key combined with the letter that follows. For example:
- To save a file, press CTRL+O and press enter after having filled out the correct file name. When editing a file, the file name is often filled out for you and you only need to press enter.
- To exit, press CTRL+X.
Most options also have explanations written besides them and there’s even a help option.
Getting help
If you need to know the arguments available for a certain command, you can type the command followed by ‘–help’. For example, to get the available options for ‘cd’, you type:
cd –help
Notice the space in between.
apt
This is the one command that’s specific to Debian-based distributions. ‘apt’ is a package management tool and it a stripped down version of ‘aptitude’, which is the full tool.
To install a package with apt, you have to know the package name. Most packages names are straight-forward, like ‘apache2’ for Apache 2 and ‘nginx’ for NGINX. If you do not know the package name, use ‘apt search {package name}’ to search available packages and their descriptions.
Once you know a package name, use ‘apt install’ to install a package. For example, to install Apache2:
apt install apache2
Depending on whether you are logged in as root or a sudo user, you may have to prefix the command with ‘sudo’ (‘sudo apt install apache2’). Read more about sudo here.
Final notes
That’s it for this part of the tutorial. You now know some basic commands to find you way around a linux server. There’s plenty of more commands to learn, including some essential which you would use quite often. Those are, however, for next week!
Key in learning to work with Linux is working with it a lot. Safest thing to do it getting a test server which you can reinstall in case something goes wrong. Such a server can be used as a perfect testing area and you can safely try out any command you like.
Good luck!
Related Posts:
- How to Rapidly Install Java, OpenJDK & Oracle JDK on your VPS - December 14, 2015
- It’s been a great ride - December 14, 2015
- Cheap Windows VPS – $21/quarter 1GB KVM-based Windows VPS in 11 worldwide locations - November 30, 2015
I’m missing
man -k
hereThat’s Part II ;-)
Now I know how to change directory, thank you!
Easy, isn’t it? Now you finally know, after all those weeks of trying to figure it out ;-)
Good post Maarten. A nice little start for those using a VPS for the first time.
Maarten, how do you decide what RAM size you need and whether to go 64-bit or 32-bit?
Anything up to 2GB should work well with 32-bit. You could even say that it could theoretically save you memory to use a 32-bit OS there, but I’ve yet to see a significant difference there in real life.
I have to say though, 64-bit has sort of become a default these days so I would always pick that myself. My personal rule is to pick 64-bit for anything with 128MB of RAM and up.
You should include a description of yum alongside apt, but nice intro.
You should update the APT part, it’s apt-get, not apt ;)
Both work. apt is a high-level script built on top of apt-get / aptitude, so is suitable for new users.
Nice post Maarten, only comment is that to run nano on Ubuntu under many VPSs you first have to:
apt-get update ; apt-get install nano
as it doesn’t come pre-loaded with the distro. Cheers!
I am having problems just getting SSH to work from the IP I was given. I can only get it work from Serial Console I initiated thru control panel.
Hoping there is a provider who can help me out / point me in the right direction.
Basically I am looking for 1 of 2 things which are:
A) A VPS provider that allows port scanning. This will solely be used for finding proxies and SEO purposes.
B) Is it possible to setup your own server and host your own private proxies? I’ve been investigating into the possibility of installing Squid Proxy on a VPS, where it can then act as a proxy server and generate proxies – Is this correct?
In nano part there is example command “nano /etc/apt.sources.list” which will open new file.
Type “nano /etc/apt/sources.list” if you want to edit sources.list
Thank you for sharing good quality tutorial with us
Great tutorial. I have just started out with a VPS plan that I grabbed through an offer on this site, and then fortunately I found this tutorial. Too much helpful. Thanks :)
Isn’t it so easy ???
o not use LowEndBox for sup
Awesome blog post buddy, keep sharing
Such a great post I like it very much keep it up.
I have thought so many times of entering the blogging world as I love reading them. I think I finally have the courage to give it a try. Thank you so much for all of the ideas!