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, 
ALL=(ALL) ALL
ics ALL=(ALL) ALL 
csm ALL=(ALL) ALL 
coa 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

440 thoughts on “SSH Like A Boss

  1. This design is wicked! You definitely know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Wonderful job. I really loved what you had to say, and more than that, how you presented it. Too cool!

  2. Heya are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding knowledge to make your own blog? Any help would be really appreciated!

  3. Have you ever considered about including a little bit more than just your articles? I mean, what you say is important and everything. But imagine if you added some great visuals or videos to give your posts more, “pop”! Your content is excellent but with images and videos, this blog could definitely be one of the best in its field. Superb blog!

  4. Hey exceptional blog! Does running a blog such as this take a lot of work? I’ve no expertise in computer programming however I had been hoping to start my own blog soon. Anyhow, should you have any suggestions or techniques for new blog owners please share. I know this is off subject nevertheless I simply had to ask. Appreciate it!

  5. Hello this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

  6. Howdy! I know this is kind of off topic but I was wondering which blog platform are you using for this site? I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at alternatives for another platform. I would be great if you could point me in the direction of a good platform.

  7. Wow! This blog looks just like my old one! It’s on a completely different subject but it has pretty much the same page layout and design. Great choice of colors!

  8. My spouse and I stumbled over here coming from a different page and thought I should check things out. I like what I see so i am just following you. Look forward to looking over your web page repeatedly.

  9. First off I want to say fantastic blog! I had a quick question that I’d like to ask if you do not mind. I was curious to know how you center yourself and clear your thoughts before writing. I’ve had a difficult time clearing my thoughts in getting my thoughts out. I truly do take pleasure in writing however it just seems like the first 10 to 15 minutes are generally lost just trying to figure out how to begin. Any suggestions or tips? Many thanks!

  10. I’m really enjoying the design and layout of your blog. It’s a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a designer to create your theme? Great work!

  11. Hi there, i read your blog from time to time and i own a similar one and i was just wondering if you get a lot of spam feedback? If so how do you stop it, any plugin or anything you can recommend? I get so much lately it’s driving me insane so any help is very much appreciated.

  12. Hi I am so excited I found your blog page, I really found you by error, while I was browsing on Bing for something else, Regardless I am here now and would just like to say kudos for a tremendous post and a all round entertaining blog (I also love the theme/design), I don’t have time to read it all at the minute but I have book-marked it and also added your RSS feeds, so when I have time I will be back to read more, Please do keep up the great work.

  13. Hello! Do you use Twitter? I’d like to follow you if that would be ok. I’m undoubtedly enjoying your blog and look forward to new posts.

  14. Please let me know if you’re looking for a author for your weblog. 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 love to write some material for your blog in exchange for a link back to mine. Please blast me an email if interested. Cheers!

  15. Howdy, i read your blog from time to time and i own a similar one and i was just curious if you get a lot of spam responses? If so how do you protect against it, any plugin or anything you can recommend? I get so much lately it’s driving me mad so any help is very much appreciated.

  16. Today, I went to the beach front 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 put 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 totally off topic but I had to tell someone!

  17. Hello, i read your blog occasionally and i own a similar one and i was just wondering if you get a lot of spam remarks? If so how do you prevent it, any plugin or anything you can advise? I get so much lately it’s driving me insane so any help is very much appreciated.

  18. Very good site you have here but I was wondering if you knew of any user discussion forums that cover the same topics talked about in this article? I’d really love to be a part of group where I can get opinions from other experienced individuals that share the same interest. If you have any recommendations, please let me know. Cheers!

  19. I don’t know whether it’s just me or if everybody else experiencing issues with your website. It appears as though some of the written text in your content are running off the screen. Can someone else please comment and let me know if this is happening to them as well? This could be a problem with my browser because I’ve had this happen before. Thanks

  20. Today, I went to the beachfront 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 put 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 totally off topic but I had to tell someone!

  21. Hi! I could have sworn I’ve been to this website before but after browsing through some of the post I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll be bookmarking and checking back frequently!

  22. I know this if off topic but I’m looking into starting my own blog and was wondering what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very internet smart so I’m not 100% positive. Any recommendations or advice would be greatly appreciated. Cheers

  23. Hello! Do you use Twitter? I’d like to follow you if that would be okay. I’m undoubtedly enjoying your blog and look forward to new updates.

  24. Today, I went to the beach front 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 totally off topic but I had to tell someone!

  25. Does your site have a contact page? I’m having a tough time locating it but, I’d like to send you an e-mail. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great blog and I look forward to seeing it grow over time.

  26. Hi there! I’m at work browsing your blog from my new iphone 4! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the fantastic work!

  27. Hello would you mind sharing which blog platform you’re using? I’m looking to start my own blog soon but I’m having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something completely unique. P.S Sorry for being off-topic but I had to ask!

  28. Hey there! I’ve been reading your web site for some time now and finally got the courage to go ahead and give you a shout out from Houston Tx! Just wanted to mention keep up the good work!

  29. Have you ever thought about including a little bit more than just your articles? I mean, what you say is important and all. Nevertheless think of if you added some great pictures or videos to give your posts more, “pop”! Your content is excellent but with images and videos, this blog could undeniably be one of the most beneficial in its field. Awesome blog!

  30. I know this if off topic but I’m looking into starting my own weblog and was wondering what all is required to get set up? I’m assuming having a blog like yours would cost a pretty penny? I’m not very internet savvy so I’m not 100% sure. Any suggestions or advice would be greatly appreciated. Cheers

  31. Good day! I know this is kinda off topic but I’d figured I’d ask. Would you be interested in exchanging links or maybe guest writing a blog article or vice-versa? My website covers a lot of the same topics as yours and I feel we could greatly benefit from each other. If you happen to be interested feel free to send me an email. I look forward to hearing from you! Awesome blog by the way!

  32. Hey there this is kind of of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!

  33. Today, I went to the beach with my kids. 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!

  34. Hey there, I think your blog might be having browser compatibility issues. When I look at your blog in Chrome, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, very good blog!

  35. Do you have a spam problem on this site; I also am a blogger, and I was curious about your situation; many of us have created some nice practices and we are looking to trade methods with other folks, be sure to shoot me an email if interested.

  36. Hi! Do you know if they make any plugins to assist with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good success. If you know of any please share. Thanks!

  37. I absolutely love your blog and find many of your post’s to be exactly I’m looking for. can you offer guest writers to write content for yourself? I wouldn’t mind creating a post or elaborating on a lot of the subjects you write related to here. Again, awesome web site!

  38. Hi would you mind sharing which blog platform you’re working with? I’m planning to start my own blog soon but I’m having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something completely unique. P.S Apologies for getting off-topic but I had to ask!

Leave a Reply

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