Site icon C1CTech

Getting started with SSH

<p>In this article&comma; we will talk about what is SSH&comma; how it works&period; We will also talk about when we use SSH and the different encryption techniques used in SSH in detail&period;<&sol;p>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">SSH Introduction<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>SSH  or secured shell is a protocol&period; Now&comma; what does it mean&quest; You may have heard about other protocols like HTTP&comma; FTP&comma; HTTPS&period; These all are ways to connect two computers and have a shared agreement on how to communicate between the two&period; That is the protocol or language that they can speak and SSH is a secure way for machines to communicate with one another&period; For example<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">HTTP &lpar;HyperText Transfer Protocol&rpar;&colon;<&sol;span><&sol;strong> It allows you to send files over the internet like HTML&comma; CSS and javascript files between browser and server&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>FTP &lpar;File Transfer Protocol&rpar;&colon;<&sol;strong><&sol;span> It allows you to transfer computer files between client and server on a computer network&period; It is often used when you upload files something like Hostgator or a generic hosting platform from your computer&period;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">HTTPS &lpar;HyperText Transfer Protocol Secure&rpar;&colon;<&sol;span><&sol;strong> It is similar to HTTP but it is encrypted that means third parties cannot read the messages being transferred if they intercept the messages&period;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">SSH &lpar;Secure Shell&rpar;&colon;<&sol;span><&sol;strong> SSH is also a protocol that allows us to communicate between the two computers over the internet&period; It allows a user to share files as well as control and modify remote computer over the internet&period; It was created as a secure way of communication which again encrypts all data so that bad actors can&&num;8217&semi;t monitor you&period;<&sol;p>&NewLine;<p><strong>Now&comma; what is the difference between HTTPS and SSH because they are both a form of communication and they are both encrypted&period;<&sol;strong><&sol;p>&NewLine;<p>Just like web browser uses HTTPS protocol to talk with servers and display websites&period; A shell needs a certain protocol to enable data exchange or communication between two devices and not just a browser and a server&period; And that&&num;8217&semi;s why SSH is called <strong><span style&equals;"color&colon; &num;008000&semi;">Secure Shell protocol<&sol;span><&sol;strong>&period; Its a protocol used over a shell and if you remember a shell unlike a browser allows you to talk to the operating system&period; With SSH you can communicate with another machine somewhere in the world through our terminal&period;<&sol;p>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">How SSH Works<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>We have talked about SSH but how exactly do we use it&quest; It&&num;8217&semi;s actually quite simple&period; If you’re using Linux or Mac&comma; then using SSH is very simple&period; But If you use Windows&comma; you will need to utilize an SSH client to open SSH connections&period; The most popular SSH client is <span style&equals;"color&colon; &num;0000ff&semi;"><b><span style&equals;"color&colon; &num;008000&semi;">PuTTY<&sol;span>&comma; <&sol;b><span style&equals;"color&colon; &num;000000&semi;">learn<&sol;span><&sol;span> more about it <span style&equals;"color&colon; &num;0000ff&semi;"><strong><a style&equals;"color&colon; &num;0000ff&semi;" href&equals;"https&colon;&sol;&sol;mediatemple&period;net&sol;community&sol;products&sol;dv&sol;204404604&sol;using-ssh-in-putty-">here<&sol;a><&sol;strong><&sol;span> and for <strong><span style&equals;"color&colon; &num;008000&semi;">Windows 10<&sol;span><&sol;strong> go <span style&equals;"color&colon; &num;0000ff&semi;"><strong><a style&equals;"color&colon; &num;0000ff&semi;" href&equals;"https&colon;&sol;&sol;www&period;howtogeek&period;com&sol;336775&sol;how-to-enable-and-use-windows-10s-built-in-ssh-commands&sol;">here<&sol;a><&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<h4><span style&equals;"color&colon; &num;0000ff&semi;"><strong>SSH Command<&sol;strong><&sol;span><&sol;h4>&NewLine;<pre><strong>ssh &lbrace;user &rcub;&commat;&lbrace;host&rcub;<&sol;strong><&sol;pre>&NewLine;<p>We have to run the SSH command with whatever user we want to reach at whichever host that is whichever computer IP address we want to get to&period; The SSH command consists of 3 different parts&period;<&sol;p>&NewLine;<p>The <span style&equals;"color&colon; &num;0000ff&semi;"><strong>ssh<&sol;strong><&sol;span> key command instructs your system that you want to open an encrypted secure shell connection&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>&lbrace;user&rcub;<&sol;strong><&sol;span> represents the account you want to access&period; For example&comma; you may want to access the <span style&equals;"color&colon; &num;008000&semi;"><strong>root<&sol;strong><&sol;span> user&comma; which is basically synonymous for a system administrator with complete rights to modify anything on the system&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;0000ff&semi;"><strong>&lbrace;host&rcub;<&sol;strong><&sol;span> refers to the computer you want to access&period; This can be an IP Address <span style&equals;"color&colon; &num;000000&semi;"><strong>&lpar;e&period;g&period; 345&period;783&period;20&period;19&rpar;<&sol;strong><&sol;span> or a domain name <span style&equals;"color&colon; &num;000000&semi;"><strong>&lpar;e&period;g&period; www&period;abcdomain&period;com&rpar;<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<p>Once you hit enter&comma; you will be prompted to enter the password for the requested account&period; Once you’re done typing&comma; hit enter once again&period; If your password is correct&comma; you will be greeted with a remote terminal window or connected with the remote computer and now can run commands on it&period;<&sol;p>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">When we use SSH<&sol;span><&sol;strong><&sol;h3>&NewLine;<ul>&NewLine;<li>Connecting to Github&comma; clone&comma; push&comma; pull files from their servers to your computer&period; Remember when we clone something from GitHub we have to choose any of the one option ie&period; <span style&equals;"color&colon; &num;008000&semi;"><strong>HTTPS or SSH<&sol;strong><&sol;span>&period; With HTTPS you have to enter the password all time&comma; to clone the repo&period; You don&&num;8217&semi;t have to do that with SSH&period;<&sol;li>&NewLine;<li>You can remotely access another computer&period; For example&comma; if you are at home when you need to access your computer work&comma; you can just SSH into it&period;<&sol;li>&NewLine;<li>The most important use case is you have your production app somewhere on the server and if it is deleted by somebody by mistake&period; Then you can simply SSH into the server&comma; get the project files to the server again and go through all the steps&comma; to get the app back up and running&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<h3><strong><span style&equals;"color&colon; &num;000080&semi;">Encryption Techniques used in SSH<&sol;span><&sol;strong><&sol;h3>&NewLine;<p>The significant advantage offered by SSH over its predecessors is the use of encryption to ensure secure transfer of information between the host and the client&period; <span style&equals;"color&colon; &num;008000&semi;"><strong>Host<&sol;strong><&sol;span> refers to the remote server you are trying to access&comma; while the <span style&equals;"color&colon; &num;008000&semi;"><strong>client<&sol;strong><&sol;span> is the computer you are using to access the host&period; There are three different encryption technologies used by SSH&colon;<&sol;p>&NewLine;<ol>&NewLine;<li>Symmetrical encryption<&sol;li>&NewLine;<li>Asymmetrical encryption<&sol;li>&NewLine;<li>Hashing<&sol;li>&NewLine;<&sol;ol>&NewLine;<p>&nbsp&semi;<&sol;p>&NewLine;<p><strong><span style&equals;"color&colon; &num;0000ff&semi;">Symmetrical encryption<&sol;span><&sol;strong><&sol;p>&NewLine;<p>Symmetric encryption is a form of encryption where only one <span style&equals;"color&colon; &num;008000&semi;"><strong>secret key<&sol;strong><&sol;span> is used for both encryption and decryption of a message by both the client and the host&period; SSH communicates through this shared key and that&&num;8217&semi;s how we are able to talk to one another&period; Symmetrical encryption is often called <span style&equals;"color&colon; &num;008000&semi;"><strong>shared key<&sol;strong><&sol;span> or <span style&equals;"color&colon; &num;008000&semi;"><strong>shared secret<&sol;strong><&sol;span> encryption&period;<&sol;p>&NewLine;<p>In the below diagram&comma; the client machine uses a secret key which it has to encrypt the message <strong><span style&equals;"color&colon; &num;008000&semi;">&&num;8220&semi;Helloo&&num;8221&semi;<&sol;span><&sol;strong> into a piece of code <strong><span style&equals;"color&colon; &num;008000&semi;">&&num;8220&semi;yt7&commat;&num;8&&num;8221&semi;<&sol;span><&sol;strong> and send it to the server&period; Server&comma; on the other hand&comma; receives that encrypted message and then using the same secret key &lpar;server has&rpar; it will decrypt the piece of code into its original form i&period;e<strong><span style&equals;"color&colon; &num;008000&semi;"> &&num;8220&semi;Helloo&&num;8221&semi;<&sol;span><&sol;strong>&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1184" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;symmetric&lowbar;encryption&lowbar;new&period;png" alt&equals;"symmetric&lowbar;encryption&lowbar;new" width&equals;"1447" height&equals;"781" &sol;><&sol;p>&NewLine;<p>In symmetrical encryption&comma; anyone who possesses the key can decrypt the message being transferred&period; So we have to get the key in a secure way so that other people can&&num;8217&semi;t use it or find out&period;<&sol;p>&NewLine;<&excl;-- WP QUADS Content Ad Plugin v&period; 2&period;0&period;98&period;1 -->&NewLine;<div class&equals;"quads-location quads-ad2" id&equals;"quads-ad2" style&equals;"float&colon;none&semi;margin&colon;0px&semi;">&NewLine;&NewLine;<&sol;div>&NewLine;&NewLine;<p>The secret key is created through a process known as a <span style&equals;"color&colon; &num;008000&semi;"><strong>key exchange algorithm<&sol;strong><&sol;span>&period; What makes this algorithm particularly secure is the fact that the key is never transmitted between the client and the host&period; Instead&comma; the two computers share some public pieces of data and then manipulate it to independently calculate the <span style&equals;"color&colon; &num;008000&semi;"><strong>secret key<&sol;strong><&sol;span>&period; Even if a bad person captures the publically shared data&comma; it won’t be able to calculate the Secret key because the key exchange algorithm is not known&period;<&sol;p>&NewLine;<h4><&sol;h4>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">Asymmetrical encryption<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>Unlike symmetrical encryption&comma; asymmetrical encryption is a form of encryption in which two separate keys are used for encryption and decryption&period; These two keys are known as the <span style&equals;"color&colon; &num;008000&semi;"><strong>public key<&sol;strong><&sol;span> and the <span style&equals;"color&colon; &num;008000&semi;"><strong>private key<&sol;strong><&sol;span>&period; Together&comma; both these keys form a <span style&equals;"color&colon; &num;008000&semi;"><strong>public-private key pair<&sol;strong><&sol;span>&period;<&sol;p>&NewLine;<p>In the below diagram&comma; both the client as well as the server consist of the public-private key pair&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1182" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;asymmetrical&lowbar;encrytion&lowbar;1&period;png" alt&equals;"asymmetrical&lowbar;encrytion&lowbar;1" width&equals;"1237" height&equals;"629" &sol;><&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;444444&semi;">The public key&comma; as the name suggests its public that means you can share it with anybody in the world&period; Unlike public keys&comma; private keys are absolute secrets that you should never ever shared with anybody&period;<&sol;span><&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;444444&semi;">The public key is closely linked with the private key in terms of functionality&comma; the private key cannot be mathematically computed from the public key&period; The relation between the two keys is a little bit complex that is a message encrypted by a machine’s public key&comma; can only be decrypted by the same machine’s private key&period; There is a one-way relationship between the two keys&period; <&sol;span><&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;444444&semi;">You can share the public key to anyone and bad people can also grab the public key but because there is a one-way relationship between the two keys the public key cannot decrypt its own messages&period; It&lpar;public key&rpar; can only encrypt something and it&lpar;messages&rpar; can only be decrypted by its paired private key&period; <&sol;span><&sol;p>&NewLine;<p>In the below diagram&comma; the client uses the server&&num;8217&semi;s public key to encrypt data for it&period; The server&comma; on the other hand&comma; uses its private key to decrypt the data on the other end that was encrypted by its public key&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1183" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;asymmetrical&lowbar;encrytion&lowbar;2&period;png" alt&equals;"asymmetrical&lowbar;encrytion&lowbar;2" width&equals;"1350" height&equals;"629" &sol;><&sol;p>&NewLine;<p>Similarly&comma; the client&&num;8217&semi;s public key is used by the server to encrypt the message and the client&&num;8217&semi;s private key is used by the client to decrypt the message&period;<&sol;p>&NewLine;<p>The private key must remain private for the connection to be secured and no third party must ever know it&period; The strength of the entire connection lies in the fact that the private key is never revealed&comma; as it is the only component capable of decrypting messages that were encrypted using its own public key&period;<&sol;p>&NewLine;<p>SSH utilizes asymmetric encryption in a few different places&period;<&sol;p>&NewLine;<ul>&NewLine;<li>Asymmetrical encryption is used during the <span style&equals;"color&colon; &num;008000&semi;"><strong>key exchange algorithm&comma;<&sol;strong><&sol;span> used to set up the symmetrical encryption&period; In this stage&comma; both parties produce temporary public-private key pairs and exchange the public key in order to produce the shared secret key that will be used for symmetrical encryption&period;<&sol;li>&NewLine;<li>The more well-discussed use of asymmetrical encryption with SSH comes from <strong><span style&equals;"color&colon; &num;008000&semi;">SSH key-based authentication<&sol;span><&sol;strong>&period; SSH key pairs can be used to authenticate a client to a server&period; The client creates a key pair and then uploads the public key to any remote server it wishes to access&period;<&sol;li>&NewLine;<&sol;ul>&NewLine;<p>Once a secured symmetric communication has been established&comma; the server uses the client&&num;8217&semi;s public key and generate a challenge and transmitted it to the client for authentication&period; If the client can successfully decrypt the message&comma; it means that it holds the private key required for the connection&period; The SSH session then begins&period;<&sol;p>&NewLine;<h4><&sol;h4>&NewLine;<h4><strong><span style&equals;"color&colon; &num;0000ff&semi;">Hashing<&sol;span><&sol;strong><&sol;h4>&NewLine;<p>Hashing is another form of cryptography used in Secure Shell Connections which uses hash functions to convert any form of data into a unique string of text&period;<&sol;p>&NewLine;<p>A hash is designed to act as a one-way function that is &hairsp;you can put data into a hash function and get a unique value of a fixed length&comma; but if you want to generate <span style&equals;"font-size&colon; 13&period;5pt&semi; font-family&colon; 'Open Sans'&comma;serif&semi; color&colon; &num;444444&semi;">the input from the hash then its impossible&period;<&sol;span> A unique piece of data will always produce the same hash&period;<&sol;p>&NewLine;<p><strong>One-way-hash functions differ from the above two forms of encryption in the sense that they are never meant to be decrypted&period;<&sol;strong><&sol;p>&NewLine;<p>In the below diagram&comma; the client machine uses the hash function which converts the text <strong><span style&equals;"color&colon; &num;008000&semi;">&&num;8220&semi;Helloo&&num;8221&semi;<&sol;span><&sol;strong> into a unique piece of string i&period;e <span style&equals;"color&colon; &num;008000&semi;"><strong>&&num;8220&semi;856a8ch45&&num;8230&semi;&period;&&num;8221&semi;<&sol;strong><&sol;span> which is nearly impossible to identify&period;<&sol;p>&NewLine;<p><img class&equals;"alignnone size-full wp-image-1185" src&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;wp-content&sol;uploads&sol;2019&sol;07&sol;hashing&period;png" alt&equals;"hashing" width&equals;"1350" height&equals;"629" &sol;><&sol;p>&NewLine;<p>SSH uses hashes to verify the authenticity of messages&period; This is done using HMACs&comma; or <span style&equals;"color&colon; &num;008000&semi;"><strong>Hash-based Message Authentication Codes<&sol;strong><&sol;span>&period; This ensures that the command received is not tampered with in any way&period;<&sol;p>&NewLine;<p>Using hash function each message that is transmitted must contain a MAC&lpar;M<strong>essage Authentication Code<&sol;strong>&rpar;&period; MAC is a hash generated from the symmetric key&comma; packet sequence number&comma; and the message contents&period; So let&&num;8217&semi;s say if the client is trying to send the password to the host and they have already established a symmetric key for secure communication&period; At client-side I will combine &lpar;symmetric key&comma; packet sequence number&comma; and the message contents&rpar; and pass it as input to the hash function and then it will spit out some piece of unique code&period; Now&comma; this code is sent to the host&period; At server-side&comma; to check that the message has not tampered with&comma; it uses its own symmetric key&comma; packet sequence number which they both know and also the message content and runs it through the same hash function again&period; Now it will compare the newly created hash with the old client hash and if it matches then it means that this message was not tampered with&period;<&sol;p>&NewLine;<p>The average user encounters hashing daily in the context of passwords&period; For example&comma; when you create an email address and password&comma; your email provider likely does not save your password&period; Rather&comma; the provider runs the password through a hashing algorithm and saves the hash of your password&period; Every time you attempt to sign in to your email&comma; the email provider hashes the password you enter and compares this hash to the hash it has saved&period; Only when the two hashes match you are authorized to access your email&period;<&sol;p>&NewLine;<p><span style&equals;"color&colon; &num;000000&semi;"><span style&equals;"color&colon; &num;000080&semi;"><strong><span style&equals;"color&colon; &num;000000&semi;">Thank you&period; I hope this article will help you in understanding a lot about SSH and also SSH encryption techniques in detail&period; If you want to know how to setup SSH on Github then go to<&sol;span><&sol;strong>  <a style&equals;"color&colon; &num;000000&semi;" href&equals;"https&colon;&sol;&sol;c1ctech&period;com&sol;how-to-set-up-ssh-on-github&sol;"><strong><span style&equals;"color&colon; &num;0000ff&semi;">How to setup SSH on Github<&sol;span><&sol;strong><&sol;a>&period;<&sol;span><&sol;span>&NewLine;

Exit mobile version