SSH stands for secured shall - a secured network service over an unsecured network. It is a network protocol. It provides an encrypted data communication between two computers. SSH can be used interactively to enable terminal sessions. SSH is also used in scripts to remotely and securely access data and other resources. In order to connect to remote server with SSH, you need:
1) Server IP or domain name
2) Username
3) Password
4) SSH client - I recommend PuTTY (you can easily download from internet) for windows operating system while Linux and MAC users can use OpenSSH which is mostly installed in their OS.
Useful SSH commands frequently used by developers:
>_ ssh <remote_host>
<remote_host> is an IP address or domain name that you are trying to connect to. This command assumes that your username on the remote system is the same as your username on your local system.
>_ ssh remote_username@<remote_host>
If your username is different on the remote system. You can specify by using this syntax.
Once you are connected to the server, you will be asked to provide a password. SSH works by connecting a client program to an SSH server. In above commands, SSH is the client program. The SSH server is at the remote_host that is specified.
How to configure SSH
When you change the configuration of SSH, you are changing the settings of the sshd server. In Ubuntu, the main sshd configuration file is located at /etc/ssh/sshd_config.
While it is helpful to be able to log in to a remote system using passwords, it is much better idea to set up Key-based authentication.
Key based authentication works by creating a pair of keys: a private key and a public key.
The private key is located on the client machine. The public key is placed on any server you wish to access. Please check how to generate public and private keys with PuTTY for windows and with ssh-keygen for linux and mac OS. The folder in which the private key is placed default in the windows is c:\users\<username>\.ssh while in unix based system it is under /home/<username>/.ssh
The public key is added to a special file within the user account you will be logging into called ~/.ssh/authorized_keys
When you attempt to connect using a key pair, the server will use the public key to create a message for the client computer that can only be read with private key.
The client computer then sends the appropriate response back to the server and the server will know that the client is legitimate. This entire process is done in the background after keys are correctly setup.
SSH operates on TCP port 22 by default. The server listens on port 22 though this can be changed through custom port number in sshd_config file.
>_ ssh -p 7322 remote_username@<remote_host>
If you are not connecting remote host at the default port 22, then you need to specify the custom port number in the command. The above command shows remote host is being connected at the port number 7322.
0 Comment