Page 1 of 1

How to key-based authentication for SSH session

Posted: Sun Jun 19, 2011 5:28 pm
by Ageek
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

Re: How to key-based authentication for SSH session

Posted: Sun Jun 19, 2011 8:03 pm
by Neo
Fantastic !!! Very useful article. REP+