Live data from Hacker News

SSH Examples, Tips and Tunnels

hackertarget.com

31–40 of 72 posts

Re: SSH Examples, Tips and Tunnels

#31
post #6
post #2

> localhost:~$ ssh remoteserver "cat /var/log/nginx/access.log" | grep badstuff.php It would be much more traffic (and execution time) friendly, if you put pipe and grep to "" as well, so grep would be executed on remote server and ssh won't have to send the entire log to your machine. And I'd like to highlight the overwhelming awesomeness of ~/.ssh/config file. If you haven't heard about it or use shell alias instea…

The article does touch on that optimization: In this example the grep is being performed on the local system after the log file has been pushed across the ssh session. If the file is large it would be more efficient to run the grep on the remote side simply by enclosing the pipe and grep in the double quotes.

While I myself am not a purist, some people would consider this an instance of UUOC: http://porkmail.org/era/unix/award.html

> localhost:~$ ssh remoteserver "grep badstuff.php /var/log/nginx/access.log"

Re: SSH Examples, Tips and Tunnels

#32
post #22
post #13

Great article! One minor comment though, `folder` sounds so wrong in *nix world, I'd suggest you use directory instead.

Not the author but I find it easier to type folder than directory on qwerty. Not sure about other layout.

I don't think they are really interchangeable terms in this context, one is rigth the other one is wrong

Re: SSH Examples, Tips and Tunnels

#33
post #32
post #22

Earlier quoted context omitted.

Not the author but I find it easier to type folder than directory on qwerty. Not sure about other layout.

I don't think they are really interchangeable terms in this context, one is rigth the other one is wrong

I assume Windows and MacOS use the term folder in place of directory, so at this point, I'm assuming it's generally acceptable to use either one.

Re: SSH Examples, Tips and Tunnels

#35

If you liked this article, PLEASE, PLEASE just take 10 minutes to look at the manpages for ssh(1) and ssh_config(5). SSH options are nothing we need to research about, we humans made it and we wrote documentation for it. The manpages are also exhaustive, definitive, and valid for the exact version you have installed. Please, instead of making more 'how to use SSH'-articles popular, read the manpages yourself. Reading…

I don't really want to read dictionary cover to cover to learn english.

Re: SSH Examples, Tips and Tunnels

#36
post #31
post #6

Earlier quoted context omitted.

The article does touch on that optimization: In this example the grep is being performed on the local system after the log file has been pushed across the ssh session. If the file is large it would be more efficient to run the grep on the remote side simply by enclosing the pipe and grep in the double quotes.

While I myself am not a purist, some people would consider this an instance of UUOC: http://porkmail.org/era/unix/award.html > localhost:~$ ssh remoteserver "grep badstuff.php /var/log/nginx/access.log"

The only reason I (and probably many other people) prefer cat | grep instead of just using grep is because it is much easier to change the search term this way. With cat, it’s only a ctrl-W away from using a different term. If I only used grep, i would have to move my cursor which can get pretty annoying with a long file path.

That being said, only using grep is my preferred approach (if I don’t forget it) in script and “compact lines” (I.e ssh, watch, and everything that expects the command as a string).

If you are grepping a file multiple times, I would recommend to connect to the server anyways (because it is much faster). That being said, if this is a single occurrence, and saves you from the pitfalls of using the local grep instead of the remote one, your approach is preferable in that case.

Re: SSH Examples, Tips and Tunnels

#37

If you liked this article, PLEASE, PLEASE just take 10 minutes to look at the manpages for ssh(1) and ssh_config(5). SSH options are nothing we need to research about, we humans made it and we wrote documentation for it. The manpages are also exhaustive, definitive, and valid for the exact version you have installed. Please, instead of making more 'how to use SSH'-articles popular, read the manpages yourself. Reading…

Sometimes all you need is a cheat sheet. Deep understanding of the tools is valuable, but not always have good ROI if it is not in your core task.

Especially for standard/common/trivial tasks.

It can bite your ass of course, but it is rare - and if you do something more exotic - take the time learning to minimize the chance.

Re: SSH Examples, Tips and Tunnels

#38

If you liked this article, PLEASE, PLEASE just take 10 minutes to look at the manpages for ssh(1) and ssh_config(5). SSH options are nothing we need to research about, we humans made it and we wrote documentation for it. The manpages are also exhaustive, definitive, and valid for the exact version you have installed. Please, instead of making more 'how to use SSH'-articles popular, read the manpages yourself. Reading…

My usage of manpages would increase by orders of magnitude if I knew there were examples of actual working commands in the first page. Most of the time I am not looking for an obscure parameter, but my brain just has failed to take a note of the basic syntax of the command. So why not start ssh manpage with two simple examples, how to connect to a host with username and ssh key: ssh user@example.com ssh -i ~/.ssh/id_…

indeed. I've always thought this, would be nice to see examples that might cover my need. Then read what the switches/options do.

Re: SSH Examples, Tips and Tunnels

#39
post #31

Earlier quoted context omitted.

While I myself am not a purist, some people would consider this an instance of UUOC: http://porkmail.org/era/unix/award.html > localhost:~$ ssh remoteserver "grep badstuff.php /var/log/nginx/access.log"

The only reason I (and probably many other people) prefer cat | grep instead of just using grep is because it is much easier to change the search term this way. With cat, it’s only a ctrl-W away from using a different term. If I only used grep, i would have to move my cursor which can get pretty annoying with a long file path. That being said, only using grep is my preferred approach (if I don’t forget it) in script…

> If I only used grep, i would have to move my cursor which can get pretty annoying with a long file path.

You can also do it like this:

    

Re: SSH Examples, Tips and Tunnels

#40

If you liked this article, PLEASE, PLEASE just take 10 minutes to look at the manpages for ssh(1) and ssh_config(5). SSH options are nothing we need to research about, we humans made it and we wrote documentation for it. The manpages are also exhaustive, definitive, and valid for the exact version you have installed. Please, instead of making more 'how to use SSH'-articles popular, read the manpages yourself. Reading…

[deleted]
Post reply on HN