How to key-based authentication for SSH session

Linux OS Topics
Post Reply
Ageek
Sergeant
Sergeant
Posts: 22
Joined: Sat Aug 01, 2009 10:54 am

How to key-based authentication for SSH session

Post by Ageek » Sun Jun 19, 2011 5:28 pm

SSH and key based authentication

OpenSSH was invented by the openBSD developers and now with default installation the openSSH client is installed. Server key are (private/ public) generated at the installation.

Code: Select all

	ls /etc/ssh

	ssh_configd	-> client config file
	sshd_config 	-> server config file
	ssh_host_rsa_key.pub 	-> RSA server public key
	ssh_host_rsa_key		-> RSA server private key
user specific ssh configuration is stored in ~/.ssh

Code: Select all

~/.ssh/known_host		-> server public keys
 ~/.ssh/autherized_key		-> user public keys
Example :

Code: Select all

ssh username@hostname/ip
ssh username@hostname/ip ls /tmp 
ssh -p 1500 username@hostname/ip


Authentication with keys

Create key pair

Code: Select all

# ssh_keygen -t rsa
Copy the keys to the remote server

Code: Select all

ssh_copy_id -i ~/.ssh/id_rsa.pub root@host/ip
Connect to the server without password

Code: Select all

ssh root@host/ip cat /root/.ssh/autherized.key
Secure Copy Protocol (SCP)


Copy the files securely over the ssh tunnel.

Examples:

Copy local file to a remote server

Code: Select all

scp /home/user/lab.txt root@host/ip:
Copy remote file to local machine

Code: Select all

scp -P 1500 root@host/ip:/home/user/lab.txt /home
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: How to key-based authentication for SSH session

Post by Neo » Sun Jun 19, 2011 8:03 pm

Fantastic !!! Very useful article. REP+
Post Reply

Return to “Linux”