Monthly Archives: April 2016

SSH and SSL: What’s the Difference?

SSH stands for Secure Shell, it is used to establish a secure connection to servers or other machines. This is usually done via a user name and password or a certificate. It is usually done over port 22. It allows the user to know that the traffic between two machines is encrypted.

 

SSL stands for Secure Sockets Layer and usually operates over port 443. It is usually used to connect to websites securely, without the need to authenticate for a connection. SSL is usually implemented when sensitive details are been passed to a website, such as bank details. When SSL is implemented the user can be certain that his or her details are encrypted between his or her machine.

 

SSL uses certificates to authenticate. These certificates need to be verified by a certificate authority. Once the two parties are connected the information that is being passed between the two is secured by encryption. SSL uses a handshake procedure to allow the two systems to connect. During the handshake the parties agree various things such as SSL version.

 

SSH is usually used for transferring commands onto a server in a secure fashion while SSL is typically used to secure details such as bank details securely across the internet. SSH was created to improve on Telnet which was unprotected and on FTP.

 

SSL operates on the presentation layer while SSH operates on the application layer, i.e. only what is being passed through the SSH tunnel is being encrypted.

 

SSH and SSL both use similar cryptograhy techniques such as RSA which stands for Ron Rivest, Adi Shamir and Leonard Adleman (the creators of the cryptosystem) so both are as secure as one another. However, as we saw from the discussion above, SSH and SSL are quite different in what they do.

Python: Searching CSVs and exporting rows based on string macthes

Recently I had a need to search through a CSV log file, that was thousands of rows long and find certain names that existed in the log file and copy these rows to another CSV. I had to do this for dozens of names, each of which could have dozens of matches. Instead of searching for each of these names and copying the rows to another CSV file (which would have taken hours!) I decided to write a script that would do this task in a matter of seconds:

The script below opens one CSV; the file which you want to search. It then saves a new file with the results. There is a list at the start of of the program called people. You can add your own strings here which you are looking for in your CSV file:

 

The Script


import csv

people = [‘Joe Bloggs’, ‘Tim O Reilly’, ‘Mary Bloggs’]

with open(‘users.csv’) as oldfile, open(‘report.csv’, ‘w’) as newfile:
for line in oldfile:
if any(people in line for people in people):
newfile.write(line)

Example

Say we have a log file with 1000s of rows and we want to find all activity for the users Joe Bloggs, Tim O’Reilly and Mary Bloggs. The log file may look something like this:

User Action
Joe Bloggs Login
Mary Burke login
Darren O Neill Updated post
Joe Bloggs Updated post
Tim O Reilly login
Mary Bloggs login

Now if we run the script we can see the file returned only contains the users we are interested in.

Joe Bloggs Login
Joe Bloggs Updated post
Tim O Reilly login
Mary Bloggs login