SSH Like A Boss

Hello reader,

Do you need to be a ninja hacker to use secure shells to interact with servers? Absolutely not. In fact many newcomers to webdevelopment are switching from ftp ssh plugins to terminal emulation like putty on Windows, or just firing up the bash shell on Mac or Linux.

Generally a Linux server has a file structure that acts more or less like a library filesystem, expanding from the root, to the branches associated with each function in that server tree.

On an ordinary Linux desktop the tree will include user files, folders, and code to use the functions of those files closer to the root, and outward towards the actual desktop.

From root on the desktop we might have bin, boot, dev, home, lib, tmp, usr, and so on.

Screenshot from 2016-01-14 14:42:37
The folders included in the root directory

The terminal displays only the files and folders in the relevant directory tree…

Terminal displaying relevant directories
Terminal displaying relevant directories
Terminal displaying the files within a directory
Terminal displaying the files within a directory.

Navigating the command line

To ssh into a remote machine you need the clientside IP, a login credential or “key” and the protocol you will be using may have other specific requirements; (some tunneling programs require ad hoc permissions)

To see the list of at level files and folders once you have terminal access on the remote machine simply type: ls

To change directories you can either use the cd command followed by the location or by the “slashes” i.e. cd\ vs cd/ can move through directories on some systems. cd Downloads is quicker than searching for the downloads folder but you can of course navigate to it by using the slashes and other directories in the tree. (cd/usr/Brian/Downloads)

Generally to make changes to a directory you need to be able to move files, mv, remove files, rm, copy files, cp, make directories, mkdir, find files, find, search for text within a file, grep, change permissions on files and programs, chmod, and oftener than not executing programs via command line is simply a matter of typing the name of the program; i.e. skype fires up skype etc.


Permissions by the numbers:

7 = Read + Write + Execute
6 = Read + Write
5 = Read + Execute
4 = Read
3 = Write + Execute
2 = Write
1 = Execute

Ergo 777 = read write and execute where as 744 = read only.

(This is why some upload folders deny access to their admins and why some admins “freak out” until you explain how to change that in the backend.)

So far we’ve demonstrated the simplest permissions and commands, to really get more out of the terminal or really even the server you are accessing via ssh you need a specific goal. In the following scenario you are accessing a Linux server and installing WordPress via ssh. A more in depth tutorial is included at the end of this article but the basic overview is essentially:

  1. Opening terminal or emulator and adding the ssh command as well as the credentials and login key.
  2. Changing directory to either the user bin, or the clients chosen location using the cd command.
  3. Adding the wordpress program, on Ubuntu based systems it’s done by typing sudo apt-get install wordpress after which you’ll be prompted for your password.
  4. Checking to see if the program is configured as well as installed correctly. <— #This isn’t something we’ve covered. To do it you really only need to go into the program itself by typing wordpress, after which you may need to assign nameservers and other non-local options depending on how the site is hosted.

Many other commands are listed in resources for ssh on the web, some of those resources include:

The Windows SSH program putty is available here: Putty

Another “Way more thorough” tutorial for installing WordPress via command line is available here.

Open ssh vs Putty – last night putty connected, so today we’ll talk about putty. I figured a few tips for new admins might be useful and a bit about installing tools this way on a server – because some of you are doing this even as I write this article.

Generally on new servers you are logged in as root and therefore you are probably scratching your heads over things like “sudo” triggering error messages. As Root you simply omit the sudo from any command – a command like sudo apt-get install git – becomes apt-install git.  If you are doing something that requires a ton of copy pasting you can add a user account and change a visudo file to just copy paste as the codes are written. (same logic applies to rpm etc)

Adding a user and granting sudo privileges

type useradd then the name eg:

useradd crazyexamplenonsensename
passwd crazyexamplenonsensename (This prompts a password request which asks you to add the password for this user)

Now as root type: visudo

You should get an output like below: (I added the user to line 5)

## User Aliases
## These aren't often necessary, as you can use regular groups
## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
## rather than USERALIAS
# User_Alias ADMINS = crazyexamplenonsensename,othername, 
ics ALL=(ALL) ALL 
csm ALL=(ALL) ALL 
To save in Vim press esc then type :x and press enter

Alternatively you can add nano (apt-get nano or rpm install nano -i) and add the user this way:

nano /etc/sudoers

then add:

user    ALL=(ALL:ALL) ALL

On a Ubuntu system or any with preset sudoers file, after doing:

type useradd then the name eg:

useradd crazyexamplenonsensename
passwd crazyexamplenonsensename (This prompts a password request which asks you to add the password for this user)

You can simply:

usermod -aG sudo username <—Of course this should be the name you are adding.>

Other fun things to know

Once you have done change directory or cd to get to a directory (like cd /opt) any followup cd command must exclude the directory you are in.

Example: We just typed: cd /example *But to get to example/bin from example – we only type: cd /bin because we are already in example.

./install – only works in the target directory – so if you exit and come back you do really need to remember which directory you were in when you left.

Apply this logic when installing from a git repo – “I just cloned in and told my terminal to download the files – which means I now must go to the directory it went to – to configure and install.”

In Conclusion

Once you’ve done it correctly it’s easy to remember, but it can actually be tricky at first. Many times you’ll be looking at the installation instructions and seeing sudo apt-get install git (even after you already have done so) so omit that part and move on – likewise if you are root – be root but then omit sudo from the commands.

Vim requires esc then :x then enter to save and exit.
Spread the love

1,322 thoughts on “SSH Like A Boss”

  1. Yesterday, while I was at work, my sister stole my apple ipad and tested to see if it can survive a twenty five foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is totally off topic but I had to share it with someone!

  2. Sweet blog! I found it while surfing around on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Thanks

  3. I really like what you guys tend to be up too. This sort of clever work and exposure! Keep up the wonderful works guys I’ve added you guys to blogroll.

  4. Greetings from Los angeles! I’m bored to death at work so I decided to browse your website on my iphone during lunch break. I love the info you present here and can’t wait to take a look when I get home. I’m surprised at how quick your blog loaded on my phone .. I’m not even using WIFI, just 3G .. Anyways, fantastic blog!

  5. Please let me know if you’re looking for a article writer for your blog. You have some really good articles and I think I would be a good asset. If you ever want to take some of the load off, I’d absolutely love to write some material for your blog in exchange for a link back to mine. Please send me an email if interested. Cheers!

  6. Howdy! I know this is kinda off topic however , I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog article or vice-versa? My website discusses a lot of the same subjects as yours and I think we could greatly benefit from each other. If you’re interested feel free to shoot me an email. I look forward to hearing from you! Great blog by the way!

  7. Greetings! I know this is kinda off topic however , I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog article or vice-versa? My website goes over a lot of the same topics as yours and I feel we could greatly benefit from each other. If you are interested feel free to send me an email. I look forward to hearing from you! Great blog by the way!

  8. Hey there! Quick question that’s entirely off topic. Do you know how to make your site mobile friendly? My weblog looks weird when viewing from my apple iphone. I’m trying to find a theme or plugin that might be able to correct this issue. If you have any suggestions, please share. Cheers!

  9. Hmm it looks like your site ate my first comment (it was super long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to everything. Do you have any recommendations for inexperienced blog writers? I’d definitely appreciate it.

  10. At this time it seems like WordPress is the best blogging platform out there right now. (from what I’ve read) Is that what you are using on your blog?

  11. Thanks for your personal marvelous posting! I truly enjoyed reading it, you could be a great author.I will ensure that I bookmark your blog and will eventually come back someday. I want to encourage continue your great job, have a nice evening!

  12. I enjoy what you guys are usually up too. Such clever work and reporting! Keep up the great works guys I’ve incorporated you guys to my own blogroll.

  13. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to create my own blog and would like to know where u got this from. cheers

  14. Very interesting subject , thankyou for putting up. “Experience a comb life gives you after you lose your hair.” by Judith Stern.

  15. Woah! I’m really enjoying the template/theme of this blog. It’s simple, yet effective. A lot of times it’s hard to get that “perfect balance” between usability and visual appearance. I must say you have done a awesome job with this. Also, the blog loads extremely fast for me on Safari. Exceptional Blog!

  16. I’m really enjoying the theme/design of your web site. Do you ever run into any web browser compatibility issues? A handful of my blog visitors have complained about my website not operating correctly in Explorer but looks great in Safari. Do you have any suggestions to help fix this problem?

  17. I enjoy what you guys are up too. This kind of clever work and coverage! Keep up the excellent works guys I’ve added you guys to blogroll.

  18. Today, I went to the beach with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  19. Hi! Do you know if they make any plugins to protect against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions?

  20. My partner and I absolutely love your blog and find a lot of your post’s to be just what I’m looking for. Does one offer guest writers to write content available for you? I wouldn’t mind producing a post or elaborating on a number of the subjects you write concerning here. Again, awesome web site!

Leave a Reply

Your email address will not be published. Required fields are marked *