Need Hosting? Try ours, it's fast, reliable and feature loaded with support you can depend on.
View PlansThere are times when we have access to physical servers and we can login directly from the server console in front of the server, or at least next to the server via KVM console. But, most of the time we don't have access to the physical server so that we have to login remotely to the server. In this tutorial we'll learn how to login remotely to a Linux Server using Secure Shell (SSH). Of course, you can also use this tutorial as guide to login to *NIX family operating systems as long as they have SSH installed.
The most simple way to login to Linux Server is using a password as an authentication mechanism. In this section we'll learn how to login to Linux server using a username and password pair.
Linux, MacOS X and most UNIX variants have SSH installed by default, you don't need to install any additional packages unless you only install the minimalist package that does not install openssh package. In this tutorial I assume that you already have ssh client installed.
To login to a Linux server using ssh you can use the command below :
$ ssh username@server
Another way to login is using the -l option for username :
$ ssh server -l username
In case you need to access a server that is not using SSH default port (22), you can specify an SSH server port number using -p
option. In the example below the SSH port is 2222.
$ ssh server -l username -p 2222
In the example below we try to login to server 128.199.138.34 using username root
.
$ ssh 128.199.138.34 -l root
The authenticity of host '128.199.138.34 (128.199.138.34)' can't be established.
RSA key fingerprint is 90:8c:7d:f8:ae:1a:09:60:44:08:3b:d9:c9:f7:c4:76.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '128.199.138.34' (RSA) to the list of known hosts.
root@128.199.138.34's password:
The warning above is shown if you are connecting to the server for the first time. The SSH client will check the authenticity of the server by checking the SSH fingerprinting. Since this is first time connection, SSH does not have any record of this server fingerprint and wil ask you whether you want to trust this server or not.
You can type yes
on the question above and input your password.
If you have logged into this server before and you get this message again there are several possibilities that could happen :
Now we'll learn how to login to a Linux Server from a Windows Machine using PuTTY. I assume that you already download PuTTY.
If you login to this server for the first time you will get a security alert regarding server fingerprint. If you are sure that you're connecting to the right server you can click Yes.
You have to input your username and password to login.
In the section above, we already learned how to login using username and password pair. In this section we'll learn how to login without password, we'll use keypair instead.
First thing that we have to do is creating keypair. We'll get a private and public key. You have to keep your private key secure while you can use the public key on the server. You can use the same private & public key on multiple servers.
To generate keypair on MacOS X and Linux, you can use comand below :
ssh-keygen -t rsa -b 2048 -C youremail@yourdomain.com -f keyfile
-C
options will allow you to give comment for this keypair, this is -f
option allow you to specify filename for the keypair.
This process will create two files, since we use filename keyfile
above, ssh-keygen will create keyfile
and keyfile.pub
.
You might already guess the one with the .pub
extension is public key and the one without extension is your private key.To copy public key to server, we can use scp program. We'll learn a little bit more about using scp on the section below. You can run command below to copy keyfile.pub
that you just generated to a server:
$ scp keyfile.pub username@server:~
The ~
(tidle) symbol above means home. So this command will copy the public key to the user home directory.
After copying the file you need to login to the server and run command below on the server:
$ mkdir ~/.ssh
$ cat keyfile >> ~/.ssh/authorized_hosts
I recommend moving your private key to ~/.ssh
on your computer. After that, change the file permission to 400
. This will make the file only readable by you, group and other users cannot read this file.
$ mv keyfile ~/.ssh
$ chmod 400 keyfile
Now the keypair is ready to be used to login to the server. You can use the ssh command below :
$ ssh -i keyfile username@server
The -i
option will tell SSH which private key to use.






.pem
format, you can choose menu Conversion -> Export OpenSSH Key 

~/.ssh/authorized_keys
on the server 

In this section we'll learn how to copy files and or folders to a Linux server and vice versa. Linux and MacOS X also have scp
program installed by default so you don't have to install additional program.
To copy a single file from our computer to a server, we can run :
$ scp data.txt @:/path/to/destination
To copy a folder and it's contents including other folders you can use option -r
(recursive). Below is sample of the command to copy folder data
to server.
$ scp -r data @:/path/to/destination
You can copy files and/or folders from a Windows client to Linux Servers and vice versa using WinSCP. You can choose between portable executable or installable WinSCP.



We can also run one off commands from our computer to the server. We can use -C
option on ssh. You can only use this option with SSH client on Linux or MacOS X. PuTTY, even if you run it from the commmand prompt does not have such option.
For example. to check process on server, instead of logging in and run ps
, you can run the command below from your computer :
$ ssh username@server -C "ps"
In this tutorial we've learn how to connect via SSH from Windows, Linux and MacOS X machine. We also learned how to do password-less login and run remote commands on the server from the computer.
Need Hosting? Try ours, it's fast, reliable and feature loaded with support you can depend on.
View Plans
Related Posts
Comments