Password based Authentication are considered to be vulnerable in the Network world. You are highly recommended to use ssh key based Authentication. SSH uses public key cryptography, that uses public key and private keys.
On the client Machine:
$ ssh-key-get -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/mac/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/mac/.ssh/id_rsa.
Your public key has been saved in /Users/mac/.ssh/id_rsa.pub.
The key fingerprint is:
14:87:b3:26:cc:eb:79:05:09:97:16:35:3e:f3:1e:9b mac@Macs-MacBook-Pro.local
The key’s randomart image is:
+–[ RSA 2048]—-+
| o=+ |
| . *+ . |
| o +.++ |
| +.= + |
| +S. o |
| . .. + |
| . . . E |
| o . |
| . |
+—————–+
Macs-MacBook-Pro:~ mac$
Server Machine:
- In the server, copy the public key(id_rsa.pub) inside ~user/.ssh/ as authorized_keys.
- Edit /etc/ssh/sshd_config to reflect PasswordAuthentication no.
- From the client you can ssh as ssh -i id_rsa user@server.
- For protecting the private key, you can use ssh pass phrase. Which acts as extra security features for ssh.
Note: Private key is used in the client, you used to access the system, the public key remained in the Server, as authorized_keys.
Resume scp:
Sometime we may have to resume the scp when connection are terminated accidentally. It can be easily done with the use of rsync: rsync --partial --progress --rsh=ssh user@host:/Remote_File Local_File
Rsync:
rsync is a file transfer program in UNIX based system that synchronize the files and directories from one system to another. It uses the delta encoding when possible to minimize the data transfer time.
- rsync -alovzrP –delete -e ssh user@host:Remote_File Local_File
- rsync -alovzrP Local_File user@host:/Remote_File
rsync Push Operation:
Pushes directory from local system to remote system.
rsync -a ~/dir1 username@remote_host:destination_directory
rsync Pull Operation:
rsync -a username@remote_host:/home/username/dir1 place_to_sync_on_local_machine
Pull directory from remote system to local system.
Important Note:
rsync -a dir1/ dir2
This is necessary to mean “the contents of dir1
“.