This post describes how to connect a Mac OS X using SSH Protocol. The SSH used to directly connect in Linux system, in order to access from a command line, set permissions, copy files, make changes.

SSH Login:

Simple syntax to use ssh login,

ssh   -p  port_number  username@ip_address 

Mac default ssh port number is 22. So, just run the below command on Terminal windows
 

$ ssh  -p 22 thelinuxfaq@192.168.1.128

The authenticity of host '192.168.1.128 (192.168.1.128)' can't be established.
RSA key fingerprint is a3:4d:54:03:dd:f6:c3:4f:20:eb:e4:ce:b1:8d:ce:4d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.128' (RSA) to the list of known hosts.
Password:


Like to see who is logged into your system and what they are doing use command "w" which means who. 
 
Mac-mini:~ thelinuxfaq$ w

18:01  up  6:10, 2 users, load averages: 2.94 2.48 2.11
USER           TTY      FROM              LOGIN@  IDLE WHAT
thelinuxfaq console  -                 11:53   6:07 -
thelinuxfaq s000     192.168.1.200     18:01      - w


How to Reset the Root Password:


How to Reset the Root Password,

Give the command "sudo su -" and give to the your user account password,

Same as Linux system possible to reset the root password using the "passwd" command line. 
 
Mac-mini:~ thelinuxfaq$  sudo su -
Password:  ENTER_USER_PASSWORD

 
Mac-mini:~ root#  passwd 

Changing password for root.
New password:  ENTER_ROOT_PASSWORD
Retype new password: RETYPE_PASSWORD  


How to Change Default SSH Port MAC

It's a very simple process to change the SSH port number, open the /etc/services file and find out the line ssh, previously explained that the default port is 22, Now let change to 10141
 
Mac-mini:~ root# vim /etc/services

#                          Jon Postel <postel@isi.edu>
ssh              22/udp     # SSH Remote Login Protocol
ssh              22/tcp     # SSH Remote Login Protocol

Change to

#                          Jon Postel <postel@isi.edu>
ssh              10141/udp     # SSH Remote Login Protocol
ssh              10141/tcp     # SSH Remote Login Protocol


Now, save the file, press key  ESC and enter 

:wq!

We need to restart the ssh service after changing the port number,

Restart SSH:
 
# sudo launchctl unload  /System/Library/LaunchDaemons/ssh.plist

# sudo launchctl  load /System/Library/LaunchDaemons/ssh.plist

unload        Unloads a service or directory of services.

load            Bootstraps a service or directory of services.
    

Now, let's login into your system with another port number which has been changed for SSH,
 
$ ssh -l root 192.168.1.128 -p 10141

Password:
Last login: Tue Jan 12 18:20:40 2016 from localhost
Mac-mini:~ root# 


How to Find SSH Connection:

"netstat" command is very helpful to view network connections on Mac.
 
Mac-mini:~ root# netstat -ap tcp | grep ssh

tcp4       0      0  192.168.1.128.ssh      192.168.1.200.55790    ESTABLISHED
tcp4       0      0  localhost.ssh          localhost.52772        ESTABLISHED
tcp4       0      0  localhost.52772        localhost.ssh          ESTABLISHED
tcp6       0      0  *.ssh                  *.*                    LISTEN     
tcp4       0      0  *.ssh                  *.*                    LISTEN     
tcp4       0      0  192.168.1.128.ssh      192.168.1.200.55789    ESTABLISHED

or
 
Mac-mini:~ root# netstat -atp tcp | grep -i "listen"

tcp6       0      0  *.ssh                  *.*                    LISTEN     
tcp4       0      0  *.ssh                  *.*                    LISTEN     
tcp4       0      0  localhost.49332        *.*                    LISTEN     
tcp4       0      0  localhost.15292        *.*                    LISTEN     
tcp4       0      0  localhost.29754        *.*                    LISTEN     
tcp4       0      0  *.kerberos             *.*                    LISTEN     
tcp6       0      0  *.kerberos             *.*                    LISTEN     
tcp4       0      0  localhost.ipp          *.*                    LISTEN     
tcp6       0      0  localhost.ipp          *.*                    LISTEN     
tcp4       0      0  *.ftp                  *.*                    LISTEN     
tcp6       0      0  *.ftp                  *.*                    LISTEN     
tcp4       0      0  *.microsoft-ds         *.*                    LISTEN