Latest Updates: os x

  • SSH Client: Automatically Connect to a Servers’ Non-Standard Port

    10:18 on August 2, 2009 | 0 Comments Tweet This! | Digg This!
    Tags: , , os x,

    If you run an SSH server, or many SSH servers, then you may have set the SSH daemon to run on a non-standard port. SSH normally listens on port 22, but with the large amount of script/bot attacks now on this port, attempting random logins, changing it to something different is a quick way to stop the majority of these automated attacks.  I’ve detailed this in another post here.

    Once you’ve done this, though, you probably get bored with having to specify the port every time you connect by typing ssh -p 1234 hostname or scp -P 1234 hostname (where 1234 is the port SSH is running on hostname) – I know I do!

    You can get around this problem, by using the ~/.ssh/config file (config in the .ssh directory in your home directory).

    You can add multiple hosts to this file, along with their port, so you can simply ssh hostname and it’ll connect  using whatever port is set in that file.

    The entry you need to add is:

    Host host.example.org
      Port 1234

    Where host.example.org is the hostname you SSH too (if you SSH to an IP address, then this will need to be set here) and Port 1234 is the port number SSH is running on hostname.

    Once this is done, you’ll be able to:

    ssh host.example.org

    … and it’ll know that you need to connect on the port set in the file.

    You can add multiple hosts to this file, if you access multiple SSH servers:

    Host host.example.org
      Port 1234
    Host host2.example.com
      Port 4567

    Give it a try – it’s certainly saved me some time!

    You may also want to checkout another post on droptips.com with further options for the ~/.ssh/config file:  http://droptips.com/ssh-client-saving-server-configuration-alias-port-username

     
  • Access Your OS X Clipboard from the Command Line

    13:00 on July 29, 2009 | 0 Comments Tweet This! | Digg This!
    Tags: os x,

    There may be times when you need to access whatever is on your clipboard in a Terminal; maybe a particularly long URL for example.  And, there may be times when you want to put things on to the clipboard from a Terminal.

    Reading the Clipboard

    As it’s going to be text on the clipboard (even if it’s an image, it’ll just be the file name if you use this command), you can access it using the command pbpaste:

    $ pbpaste
    
    http://droptips.com/

    So in this case, I have the text “http://droptips.com” on my clipboard, but what if I want to access that from a string of commands?  (I’m using curl as an example from another post)

    $ curl -Is `pbpaste` | head -n1

    By placing ` ` around the pbpaste command, it will run, and whatever it returns will be used instead.  So, the above command in this instance will actually run:

    $ curl -Is http://droptips.com | head -n1

    Of course, you may want to just run a few stats on the contents of your clipboards, and you can also do this using the wc command I posted about.  You can run pbpaste and pipe it through the wc command as follows:

    pbpaste | wc -w

    This will return the amount of words currently on the clipboard.

    Writing to the Clipboard

    But what if you want to get content onto the clipboard?  We use the pbcopy command.

    So if I want to get the contents of a text file onto the clipboard, I could cat the file and pipe it through to pbcopy as follows:

    cat myfile.txt | pbcopy

    Anything which gets passed to pbcopy this way, will be on the clipboard.

    Likewise, if I want to put a single line of text onto the clipboard, I could use the echo command:

    echo "I want this on the clipboard" | pbcopy

    As this is the normal clipboard, this content is available using the normal paste commands and of course pbpaste.

    So if you ever find yourself needing to use the clipboard from a Terminal, then pbpaste and pbcopy are the commands to do it!

     
  • Quick command to check the status of a URL (Linux, BSD, OS X)

    22:54 on July 28, 2009 | 0 Comments Tweet This! | Digg This!
    Tags: , , os x,

    There may be times when you just want to do a quick check to see whether a web site is up, and/or what status message the web server is showing. This won’t actually show you if the page it served up is correct or not, purely the web server status code on whether or not it served something/anything/nothing!

    There are lots of status codes for web servers, and they are detailed here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

    So, to be able to see the status message, and to check if a host is up or not, we can use the curl command.  curl is installed by default on OS X, but you may need to install it on your Linux distribution or BSD installation.

    So, to do a quick check from a command line:

    curl -Is http://droptips.com | head -n 1

    And you’ll get something back similar to:

    HTTP/1.1 200 OK

    Status code 200 is “OK”.

    HTTP/1.1 200 OK

    As another example, to show you how this will display different status codes, you’ll notice that if you visit: http://www.droptips.com you are redirected to http://droptips.com, purely because I prefer not to have www in the URL.  I do this by implementing a 301 (Permanently moved) from within Apache for any client going to http://www.droptips.com:

    $ curl -Is http://www.droptips.com | head -n 1
    HTTP/1.1 301 Moved Permanently

    As you can see, the web server returned a 301, and this is shown.

    curl can also take full URLs, so you can check whether or not a particular page/path is being served or not:

    curl -Is http://droptips.com/tag/tips/ | head -n1
    HTTP/1.1 200 OK

    So if you want to see if that new redirect is working, or just to see if your web server is up and serving requests, give curl a go!  This is just a basic overview of one thing you can do with curl - it’s a very flexible command, and can be used in a number of scenarios, some of which I will post about in the future.