× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

SSH shell: He says "Let there be colors" Shell Beginner Guid

alouch47
Guide

SSH shell: He says "Let there be colors" Shell Beginner Guid

Modified : 2010-12-31
Hi everyone.

Not quite sure it has already been posted, so I thought I just share some tips.
It's just "basic" Linux knowledge, so it won't be of great interest for those who are already familiar with this, but others may find this useful. I won't just throw what to modify, but I'm going to explain some of the very basic Linux commands too.

As you may already know, you NAS is accessible via SSH, but the basic shell access is rather "austere" & first time users might be unwilling to use shell access due to that fact.
So this "howto" is just about putting some life in it.
Pre-requisites :

  • SSH addon

  • APT addon (may be already installed on your NAS)

  • A SSH access software. For Win users, use the great PuTTY

  • basic linux knowledge will help


:idea: Tip for the first time users.

  • To copy/paste text in the linux terminal/shell : Just select the text you want to copy, as in windows, and THAT'S ALL (selected text is automatically copied into memory). To paste, just right-click, and the text will be pasted at the cursor position (not the mouse cursor position, the terminal cursor position, so be careful).

  • To cancel an operation, input CTRL+C

  • To logout of a terminal, input CTRL+D (when you're at shell prompt, ie not editing a file or running an operation)

  • With Linux, directory structures are written with forward slashes "/" as opposed to windows where it is backslashes "\". So directories are accessed with cd /directory1/directory2 ...


Let's start with the beginning.

When you access you readynas via SSH, after login in successfully, you end up to the linux shell.
It's called "BASH" (acronym for "Bourne-Again Shell") (For those interested in reading, here is the Wikipedia link).
I'll assume you'll use PuTTY from now on. (Sorry Mac users, should be pretty the same for your ssh soft too)

Once logged in, you get something like this :

login as: root
Authenticating with public key "root@Hydra"
Passphrase for key "root@Hydra":
Last login: Fri Sep 3 09:45:07 2010 from 172.21.0.12
Last login: Fri Sep 3 10:12:10 2010 from 172.21.0.12 on pts/1
Linux Hydra 2.6.33.6.RNx86_64.2.1 #1 SMP Tue Jul 27 13:21:19 PDT 2010 x86_64 GNU/Linux
Hydra:~#

Here "Hydra" is the name of my ReadyNas Pro, so you should see a
YouNASName:~#

That's the prompt.
the "~" mean you're in your "home directory", so if you've logged in as "root" you should be in the "/root" folder.
You can check in what folder you're in by issuing the "pwd" command
:!: "/root" is the home folder for the user "root", not to be confused with "the root folder" which is the base directory ("/")

Ok, now go to the root folder "/", and input a "ls" ("list") command to see what's in it.

Hydra:~# cd /
Hydra:/# ls
addons-config dev home lost+found opt sbin usr
backup Documents initrd media proc sys var
bin etc lib mnt ramfs tmp webroot
c frontview lib64 Mx500 root USB
Hydra:/#

:?: Yeah, whatever, just plain grey text over a black background... Not really appealling :roll:
Don't worry, as we're gonna remedy to this !

Part 1 : Improve the shell
First of all, we need to edit "bash" profile file, so we can pass options to it.
The file's located under the /root folder (if you're logged in as "root") and it's called ".bashrc"
Hydra:/# cd /root/
Hydra:~# ls
Hydra:~#

:?: WTF ?? It's all empty ??
Ok so you won't find it if you input just a "ls" command, as files beginning with a dot "." are considered hidden by the system.
You have to input a "ls -a" ("a" as in "all") to see everything
Hydra:~# ls -a
. .bash_history .ncftp .ssh .viminfo .VirtualBox
.. .bashrc .profile .vim .vimrc
Hydra:~#


Let's edit the file, and put some lines in it.
We'll use the "vi" text editor, a basic editor available in almost (if not all) linux distro.
For the moment, "vi" we'll be basic too, but we'll enhance it in the next part of this howto
Hydra:~# vi .bashrc

The file will be pretty empty when you open it first time
So lets fill the following lines in, so you final file is as mine :
To input lines in "vi" you have to tap the "insert" key on your keyboard.
It'll then read as "I" in the bottom-left corner of the screen. If you tap "insert" a 2nd time, it'll read "R" instead which mean "Replace" so be careful. For numbers input DO NOT USE THE NUMPAD as the result may be unexpected. Use the keys above the keyboard instead
To exit "edit" mode, just press the "Esc" key on your keyboard.
Here is the file as it should look when you're done editing

# ~/.bashrc: executed by bash(1) for non-login shells.

# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
#
# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

:!: Be careful with the line "eval "`dircolors`"" because "dircolors" is enclosed in single backquote "`" (= Grave accent) and not single quote " ' ". If you're unsure how to type it, just copy/paste the text above in you file

To do operations in "vi", you have to escape input mode (by tapping the "Esc" key on you keyboard) and then tap ":"
You'll see that ":" will appear on the bottom-left corner of the screen.
Then input "wq" (without the quotation mark) for "write & quit"
"Vi" will save the file and return you to the shell.
:!: If you've made a mistake and don't know how to go back, input ":q!" (without the quotation mark) to "force exit" without saving, and just try again

Some explanations. In the above file, we've passed options to bash, to tell it to render a color coded display.
Moreover, we have created "Alias". Alias are useful to shorten commands for example, as it's the case here.
For example, we have aliased the "ls -l" command (ls = show dir content, -l in ordered vertical list with file/directory details) to "ll"
So if you type "ll" at the shell prompt, it'll be as if you've typed "ls -l". You might not see the point in doing this right now, but when you'll be a little more used to the Linux environment, you'll see that's it's very useful to have full detailed view of a file/directory.

:?: When I type "ll", it says "command not found"
Yes, the modifications are not applied immediately, you'll see them when you'll logout/login to PuTTY.
But for now, stay logged in, as we have more to do.
You can try the "ls -l" command to see how the result looks like.

Part 2 : Improve "Vi"

This part is the simpler one now that you've learned a little bit more. We're going to replace our basic "Vi" with it's enhanced version called "Vim"
With APT ready to use, it's very simple to install new "packages" (equivalent of Win/Mac executables)
We're going to install the enhanced version of the "Vi" editor.
To do this, just type the following command at the prompt
Hydra:~# apt-get install vim vim-doc vim-scripts

This will install all the necessary packages plus some others (the doc, which can be very useful)

Once everything is installed, we have to do one more small modification.
Go to you home folder by issuing a "cd" without any char after
type a "ls -la" and see if you have a file called ".vimrc"
If it's not the case, simply make one, by issuing "touch .vimrc"
:!: At the left of each line what you see are permissions of each file/folder. Folders are indicated with a "d" as the first letter
Hydra:/# cd
Hydra:~# ls -la
total 52
drwxr-xr-x 6 root root 4096 2010-09-06 10:54 .
drwxr-xr-x 23 root root 4096 2010-09-02 12:27 ..
-rw------- 1 root root 10290 2010-09-03 16:05 .bash_history
-rw-r--r-- 1 root root 396 2010-09-02 17:26 .bashrc
drwxr-xr-x 2 root root 4096 2010-08-18 21:53 .ncftp
-rw-r--r-- 1 root root 110 2004-11-10 17:10 .profile
drwx------ 2 root root 4096 2010-08-18 21:48 .ssh
-rw------- 1 root root 3885 2010-09-06 10:54 .viminfo
-rw-r--r-- 1 root root 10 2010-09-02 17:29 .vimrc
drwxr-xr-x 2 root root 4096 2010-09-02 20:46 .VirtualBox

Hydra:~# touch .vimrc


This file will contain only one parameter for the moment, so it is necessary to open it and edit it, we can fill it with the following command:
Hydra:~# echo "syntax on" >> .vimrc

The "echo" command is used to sort of "write" the text inside the quotes somewhere. By default, it write it to the display.
By using the ">>" we're telling echo to write the text at a precise location. This location is in fact the ".vimrc" file.
So our command write the text in quotes into the file.
This command will tell "Vim" to use syntax highlighting which is very useful when reading trough a file.

One more thing and we're done.
We have to tell the system to now use the "vim" executable instead of the "vi" one.
Go to the "/bin" folder which contains some of the executable files of the system.
Type a "ls -l vi"
Hydra:~# cd /bin
Hydra:/bin# ls -l vi
lrwxrwxrwx 1 root root 12 2010-09-02 17:51 vi -> /bin/busybox
Hydra:/bin#

What you see here is called "Symbolic Link" (designated by the -> and the "l" at the beginning of the line )
It means that when you type "vi" at the command prompt, in fact the system execute a program called "busybox"
We have to modify this to call "vim" instead.
First we have to delete the existing link.
:!: Be VERY CAREFUL when deleting system files when you're logged in as root, as you might end up killing your system and restoring your NAS
Type "rm -i vi" and answer with a "y" to the question if you are sure what you're about to delete.
Hydra:/bin# rm -i vi
rm: remove symbolic link `vi'? y
Hydra:/bin#


Now we'll tell the system that "vi" should call "vim". For this we're using the "ln -s" command. The "ln" command is to create links and the "-s" parameter is for "symbolic" (as opposed to "hard links"). A symbolic link (also known as a soft link or symlink) consists of a special type of file that serves as a reference to another file or directory.
Hydra:/bin# ln -s /usr/bin/vim vi
Hydra:/bin# ls -l vi
lrwxrwxrwx 1 root root 12 2010-09-06 11:18 vi -> /usr/bin/vim
Hydra:/bin#

With this, you can continue to type simply "vi" to edit a file, and the system will automatically called "Vim"

"Et voila!" you're done! Now you have to logout and back in to SSH for all the modifications we have done to be applied to our profile.
Alternatively, you can also source (aka, re-read the file and apply modification) the .bashrc file by typing the following code into your terminal :
cd ~ ; . .bashrc

The "~" means you home-dir. So basically you just cd to your homedir, and source (reload) the .bashrc file. Be carefull, there is a space between the dots. The first is equivalent to the command "source", the second one is part of the filename you want to source.

To see how things change, you can for example go to the "/bin" folder and issue a "ll" command.
You can also try to edit your .bashrc file and see how it looks like now.


Hope you guys will find this little contribution helpful. Don't hesitate to ask questions & make criticism.
Message 1 of 22
John_Bean
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

You put a lot of effort into this, well done.

One criticism is that although your focus appears to be on Linux "newbies" you then go on to frighten them off with vi (and vim), a complete overkill for the sort of editing your target audience is likely to do.

My recommendation would be to completely ignore vi unless you're already familiar with it, instead install a simple editor like nano by typing "apt-get install nano" - this was the very first command I typed on my first ssh session 😉
Message 2 of 22
sphardy1
Apprentice

Re: SSH shell: He says "Let there be colors" Shell Beginner

"apt-get install nano" - this was the very first command I typed on my first ssh session

Completely agree - was the first for me too. Though I find vi to be like the proverbial learning to ride a bike; once learned you never forget...

But great write up nonetheless
Message 3 of 22
alouch47
Guide

Re: SSH shell: He says "Let there be colors" Shell Beginner

John Bean wrote:
You put a lot of effort into this, well done.

One criticism is that although your focus appears to be on Linux "newbies" you then go on to frighten them off with vi (and vim), a complete overkill for the sort of editing your target audience is likely to do.

My recommendation would be to completely ignore vi unless you're already familiar with it, instead install a simple editor like nano by typing "apt-get install nano" - this was the very first command I typed on my first ssh session 😉


Thanks I appreciate.

You're absolutely right, I could have spoken of Nano, but honnestly I'm not even sure I know how to use it, I mean as correctly as Vim :lol:
I've learned Linux the Slackware-vi-hard way 🙂

Sure, Vim might not be the easiest way to approach Linux, but once you know you're way round with it, it's kinda magic 😉
My point is to give people the envy to look a little further by themself. I'm just trying to remove the fright of the "first time" & show that "Yes, Linux can be Fun too"

[EDIT] Moreover, I've just remember that Nano doesn't offer colorful syntax highlighting by default, and it required A LOOOT of code in the .nanorc file to enable this. As this mini-howto was about colors too, Nano would have been more complicated to explain finally.
Message 4 of 22
John_Bean
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

sphardy wrote:
Though I find vi to be like the proverbial learning to ride a bike; once learned you never forget...


Yep, but you wouldn't learn to ride a bike just to cycle 100 yards a couple of times... 😉

Vi has many (too many to count) advantages over an editor like nano, but simple editing of a couple of config files by a beginner is absolutely not one of them!

But great write up nonetheless


Agreed.
Message 5 of 22
LrdShaper
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

Great post 🙂 I'm sure a lot of members here will find this useful

You may also add the line
shopt -s cdspell

in the .bashrc for auto-correcting minor errors in the spelling of a directory in a cd command. Assuming you have the following path "/home/lrdshaper/devel/cross/readynas_sparc/staging", typing
cd ~lrdshaper/deve/crss/readynas_sprc/staginG

will take you to /home/lrdshaper/devel/cross/readynas_sparc/staging instead of giving you a "No such file or directory" error. Cheers!
Message 6 of 22
sphardy1
Apprentice

Re: SSH shell: He says "Let there be colors" Shell Beginner

FYI: the command

apt-get install vim vim-enhanced vim-doc vim-scripts

fails - there is no package called vim-enhanced, though it doesn't appear you need it to achieve the colour syntax highlighting
Message 7 of 22
John_Bean
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

sphardy wrote:
FYI: the command

apt-get install vim vim-enhanced vim-doc vim-scripts

fails - there is no package called vim-enhanced, though it doesn't appear you need it to achieve the colour syntax highlighting


All you need to do is edit .bashrc to enable the colour. This is why I was a bit critical of all the vi-related stuff being somewhat off-putting to the beginner and not related to the job in hand. You don't even need an interactive editor to do the job (let alone vim and enhancements!) if you don't mind geek-speak instructions, but I'm a big fan of the KISS principle in general.

In this case installing and using nano as the editor is a no-brainer, completely avoiding unnecessary issues like the one you just highlighted.
Message 8 of 22
MichaelR64
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

I used WInSCP to get into the machine and found that a double click on a file brings up the default editor of winscp which is good enough for most editing in windows.
I mean stuff like editing conf files.
And i got a tree-like explorer which is pretty comfortable for a Windows guy...
Message 9 of 22
alouch47
Guide

Re: SSH shell: He says "Let there be colors" Shell Beginner

sphardy wrote:
FYI: the command

apt-get install vim vim-enhanced vim-doc vim-scripts

fails - there is no package called vim-enhanced, though it doesn't appear you need it to achieve the colour syntax highlighting


You're right, was a typo from me. "vim-enhanced" is the package name in fedora/redhat distro which I'm more used to.
I've edited the OP.
Message 10 of 22
John_Bean
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

MichaelR64 wrote:
I used WInSCP to get into the machine and found that a double click on a file brings up the default editor of winscp which is good enough for most editing in windows.
I mean stuff like editing conf files.


I'm very uncomfortable about the idea of remotely editing linux config files this way, especially if the editor is running on a Windows machine which uses a different definition of "text" in the context of text files. Much safer to run a local native editor and rely on the remote (Windows) PC to provide only the UI.
Message 11 of 22
MichaelR64
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

John Bean wrote:
MichaelR64 wrote:
I used WInSCP to get into the machine and found that a double click on a file brings up the default editor of winscp which is good enough for most editing in windows.
I mean stuff like editing conf files.


I'm very uncomfortable about the idea of remotely editing linux config files this way, especially if the editor is running on a Windows machine which uses a different definition of "text" in the context of text files. Much safer to run a local native editor and rely on the remote (Windows) PC to provide only the UI.

Winscp is aware of this and quite configurable
Message 12 of 22
goudkamp
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

Very handy, thanx! Please update the part where you say you'll need to logout / login to see the changes. This is soooo much easier:

source .bashrc
Message 13 of 22
Topper1
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

You shouldnt call this a beginners guide. I'm a beginner, and i'm looking for some help with my duo. So i start to read your post because its aimed at beginners... I only reach to the point where you talk about SSH then i'm lost. Wonder what that is..
Oooh and then i reach the pre-requisites and my head explodes.
I mean, thumbs up for the effort, but you geeks kinda need to think a bit like a total newbie if you want to write stuff for newbies. Just imagine you have to make it understandable to a guy in the jungle... Or am i way off ?
Message 14 of 22
Topper1
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

oh i forgot, is there somewhere where i can find a beginners guide to the most relevant stuff i need to know about the nas? Like i want to setup BASHPODDER, but all posts just say "Edit this and this file" without actually writing how i can edit it... where i should click...

I guess what i want is a youtube tutorial showing how its done from scratch with an out of the box DUO but thats probably a little much to ask 🙂

Thanks for a great forum though
Message 15 of 22
alouch47
Guide

Re: SSH shell: He says "Let there be colors" Shell Beginner

Topper wrote:
oh i forgot, is there somewhere where i can find a beginners guide to the most relevant stuff i need to know about the nas? Like i want to setup BASHPODDER, but all posts just say "Edit this and this file" without actually writing how i can edit it... where i should click...


So maybe bashpodder shouldn't be your first concern :roll:
If you don't even understand what's SSH is and how it works, maybe you should start by searching this forum or the internet.
Why do you guys always complain not to understand, when you don't even make the effort to try and understand.


Topper wrote:
You shouldnt call this a beginners guide. I'm a beginner, and i'm looking for some help with my duo. So i start to read your post because its aimed at beginners... I only reach to the point where you talk about SSH then i'm lost. Wonder what that is..
Oooh and then i reach the pre-requisites and my head explodes.
I mean, thumbs up for the effort, but you geeks kinda need to think a bit like a total newbie if you want to write stuff for newbies.


There are several levels of "newbiness"... As there are differences between being a newb and being completely unable to use the search bar (which is FYI located on the top right hand corner of your web browser).

And oh I forgot. It says "SHELL" beginner guide, which assume you at least know what is / howto access the shell (as there are other threads in THIS forum that explains it 😉 )

Just imagine you have to make it understandable to a guy in the jungle... Or am i way off ?

uh? no. no have computer and readynas in jungle :lol:
Message 16 of 22
alouch47
Guide

Re: SSH shell: He says "Let there be colors" Shell Beginner

goudkamp wrote:
Very handy, thanx! Please update the part where you say you'll need to logout / login to see the changes. This is soooo much easier:

source .bashrc


Thanks, i've updated the first post 😉
Message 17 of 22
RoLLER1
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

I get theese error messages when i try to install the Nano and/or the vim editor.

Anybody with an idea? 🙂

RoLLERs-NAS:~# apt-get install nano
Reading Package Lists... Done
Building Dependency Tree... Done
W: Couldn't stat source package list http://www.readynas.com readynas/ Packages (/var/lib/apt/lists/www.readynas.com_packages_readynas_Packages) - stat (2 No su ch file or directory)
W: Couldn't stat source package list http://archive.debian.org sarge/main Packag es (/var/lib/apt/lists/archive.debian.org_debian_dists_sarge_main_binary-sparc_P ackages) - stat (2 No such file or directory)
W: Couldn't stat source package list http://archive.debian.org sarge/contrib Pac kages (/var/lib/apt/lists/archive.debian.org_debian_dists_sarge_contrib_binary-s parc_Packages) - stat (2 No such file or directory)
W: Couldn't stat source package list http://archive.debian.org sarge/non-free Pa ckages (/var/lib/apt/lists/archive.debian.org_debian_dists_sarge_non-free_binary -sparc_Packages) - stat (2 No such file or directory)
W: You may want to run apt-get update to correct these problems
E: Couldn't find package nano
Message 18 of 22
danny0085
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

Here you can check out the most used linux commands

http://commands.tips-linux.net
Message 19 of 22
dbott67
Guide

Re: SSH shell: He says "Let there be colors" Shell Beginner

RoLLER wrote:
I get theese error messages when i try to install the Nano and/or the vim editor.

Anybody with an idea? 🙂

RoLLERs-NAS:~# apt-get install nano
Reading Package Lists... Done
Building Dependency Tree... Done
W: Couldn't stat source package list http://www.readynas.com readynas/ Packages...


Try running apt-get update first. This will update all of the packages and what-not:

Envious:~# apt-get update
Get:1 http://archive.debian.org etch Release.gpg [1033B]
Hit http://archive.debian.org etch Release
Ign http://www.readynas.com 4.2.13/ Release.gpg
Ign http://archive.debian.org etch/main Packages/DiffIndex
Hit http://archive.debian.org etch/main Packages
Ign http://www.readynas.com 4.2.13/ Release
Ign http://www.readynas.com 4.2.13/ Packages/DiffIndex
Get:2 http://www.readynas.com 4.2.13/ Packages [8816B]
Fetched 8817B in 1s (5876B/s)
Reading package lists... Done

Then:
apt-get install nano
Message 20 of 22
Korky
Aspirant

Re: SSH shell: He says "Let there be colors" Shell Beginner

alouch47 wrote:
Modified : 2010-12-31
Hi everyone.

Not quite sure it has already been posted, so I thought I just share some tips.
It's just "basic" Linux knowledge, so it won't be of great interest for those who are already familiar with this, but others may find this useful. I won't just throw what to modify, but I'm going to explain some of the very basic Linux commands too.
.......


very helpful to me.
made all the changes - loving the colours
thank you !!
Message 21 of 22
alouch47
Guide

Re: SSH shell: He says "Let there be colors" Shell Beginner

Korky wrote:

very helpful to me.
made all the changes - loving the colours
thank you !!


Thanks. I'm glad it helped you :thumbsup:
Message 22 of 22
Top Contributors
Discussion stats
  • 21 replies
  • 49112 views
  • 4 kudos
  • 11 in conversation
Announcements