Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SSH

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 10

using putty for connecting to the remote machine linux

ssh --ssh is a command to ligin into remote linux machines

there are 2 ways login into remote linux machins

1) with passwd
2) passwordless login

i am login without passwd that is calle passwd less comnds

=================================================
when ever i login in remote linux machine server pre-req
ipadress username passwd mandatory

i1--------------34.60.90.90-------------------linux os

------root
------sheshi
-------abc
--------xyz

syntax of you want to login from local to remote machine


ssh sheshi@34.60.90.90

we are login into 34.60.90.90 machine using of sheshi crediansls

ssh we can call it as peice of service(software)


ssh service by default it's run on port 22 by default
we are send a req to 22 port numbers

====================================================================

we are install any service on linux machine that serviceconfiguration files are
located in
/etc folder.

like java software,phython.apache2,tomcat etc...

/etc/apache2
/etc/tomcat
/etc/ssh

confguration files means : that service which port number it running etc..
information

ssh allready install all machines.

ssh configuration files stored in

/etc
/etc/ssh
inside ssh their are multiple files it related to that config files
/etc/sshd_config ----file
in sshd_config file ----i dont to run 22 port number ssh i want to change you can
change in sshd_config

in sshd_config file having


passwdauthication value yes means passwd will be asking(authicateed)
passwdauthication value no means passwd will be not-asking(passwd will not be
authicateed)

when req to that machine in machine ssh service taken that req and it check
sshd_config file
in that passwdautication yes means it will prompt for passwd--means it will ask
passwd so we can login using of passwd
no means it does not prompt for passwd ---doesnot ask passwd means we will not
login that user using of passwd

===========================================================
without username we canot login into machine

how to check ssh dir avaliable or not

ls -ld ssh
=================================================
-d ---stopt the expansion of dir
========================
publickey-----lock it having linux
privatekey---------key----it's want to who login that machine that machine having
private key

=======================
source machine required private-key
remote machine required public key
========================================
when ever we luanch a machine aws create 2 key's
1) public key
2) private key

private key given to us source machine dowloaded


public key aws given to remote machine .
=================================================
we are also create a key pairs using of ssh-keygen command
by using gitbash tool i can create using of ssh-keygen command in our local
machine.
that command allways created 2 files
public file extension .pub
private keyfiles .ppk,.pem
public key and private key both are in sink
======================================

remote machine having public key right


in machine that public key location
~/.ssh/authorized_key
=============================================
32.19.90.22
--root--/root
---sheshi---/home/sheshi
abc------/home/abc
-----------ubuntu--->/home/ubuntu

laptop:

i want to login into linux machine without passwd


ssh sheshi@32.19.90.22 ----it req go to that machine
that machine check user home dir authorized_key(public key) is avaliable
but wants to login that machine public key and private key sink
but we are not providing private key --it will thorw error

ssh sheshi@32.19.90.22--look for public key in /sheshi/.ssh/aut_key


ssh abc@32.19.90.22--look for public key in /abc/.ssh/aut_key
============================================================
which private key i want to use asking ssh commnd to us
we are telling to ssh command using of (-i) option
ssh -i "abc.pem" abc@32.19.90.22
that is meaning that command using that file we are login into machine

ssh(command we using for that command login into remote linux machines) -i(we are
tells to cmd command use this file for login) abc.pem username(using user
crediantls)
@ip(machine unique ip adress) ----this is meaning of that full command for login
into remote linux machine when we are loging username is must
=====================================================================
authorized_pubkeys having all publik keys data
key means that is file that file having some information
========================================
how many authorized_keys having in your machine ---it's posible to have multiple
l.e ---sheshi user having auth_keys
abc user having ~/abc/auth_keys
ubuntu user having ~/ubuntu/auth_keys
harsh user having ~/harsha/auth_keys
==================================================================================
most are peoples are thinking one auth_keys in machine--it is inncorect
every user having one auth_keys

=============================================================================
it is possible to have one auth_keys in multiple public keys--yes
===================================================================

production-server
90.90.90.87
------user(ubuntu)

4 elompies joind

emp1-------pk1
emp2----------pk2--
emp3-------pk3
emp4----------pk4

each and every emp give saparete pkey


i want to give ubuntu acess for every emp
in this case in ~/.ssh/auth_keys having 4(pubk1,pubk2,pubk3.pubkey4) publick keys
data.
========================================
ssh--loging into remote server user
you want to ligin user is mandatory
=====================================

ssh---passwdkey
--passwdless auth

ssh con files are avaliable in /etc/ssh/

i want to deny passwd authication to remote users


1) in /etc/ssh/sshd_config-------keep passwdauthication value=no

passwdauth=no means we want to login into server user with private-key

using private -key login is called passwd less auth

i want to allow passwd authication to remote users


1) in /etc/ssh/sshd_config-------keep passwdauthication value=yes
===================================================
how to generate keys
ssh-keygen--it will do only 2 keypair 1.pub 2) pri
===============================
all pub keys are stored loc
~/.ssh/auth_key file
==================
mu public key data stored in auth_keys ~/.ssh/auth_keys
using cmd ssh-copy-id
=================================================
how to edit files---vim it is not userfriendly
vim f1 --it will shown new thsi new file to vim , vi
not showing new file it is exsting file

maintly need vim comand option

insert
save
delete line
quit

in vi have modes

1) commnd mode
2) insert mode
3) excution mode

you want to go to file using vi

you want to inser a data using inser mode you want to go tp insert mode type (I)
YOU WANT TO SAVE U NEED TO COME OUT INSER MODE ---ESC
:W--FOR SAVING
ESC+:W
YOU WANT TO QUIT THAT FILE USEING :q
:Wq
:WQ!
BOTH ARE DIFFERNT

yy-meany yanky copy the part line


p-paste where you want
dd-delete curent line
3dd-i want to delete 3 lines from curent line
5dd-delete 5 lines from curent line
100dd -- delete 100 lines from curent line
===================
vim
i/a
esc
:w
:q
:q!
:wq!
dd
2dd
100dd
yy
3yy
p
===============================
when ec2 luanch aws download 2 key pair one assin to our local machine private key
and pub key placed in by default /home/ubuntu/.ssh/auth_keys

we can create 2 key paires and we can copy pub data in auth_keys and we can use our
private key -it is possibly
that pub data copy purpose we are using ssh-copy-id command.

==========================================
ssh-copy-id copy the .pub file data from local machine to remote machine
when ever ssh-copy-id copy .pu file req 1).pub file 2) user 3)ip 4) passwd
by default ssh-copy-id copy the .pub file in locaton ~/.ssh/auth_keys in that file
saved
================================
syntax

ssh-copy-id -i filename.pub user@ip

useradd -m -s /bin/bash sheshi


we are changing port number ssh to 2222 we are telling to git ssh using -p 2222

ssh-copy-id -i filename.pub user@ip

============================================
here,
ssh-copy-id login and copy .pub data in auth_keys ssh-copy-id using passwd
authication
here,
by default using passwd authication in system /etc/ssh/sshd_config file having
passwdauth value = no
when passwdauth=no system doesnot ask passwd system need passwdless auth only.
so we want to talk with collegu. then coluequ go to and change that value of
passwdauth = yes
then only system accepting passwd authication.
===================================================================================
=====
now,
we can use ssh-copy-id we are copy data of .pub file to remote machine .
when .pub data copied in remote machine again colegu change value yes to no.
===================================================================================
==========
we are not giving key-paires name id_rsa
by default store ~/.ssh/id_rsa.pub is_rsa
====================
ssh-copy-id user@ip we can give like that it will lookfor id_rsa
==============================
we cant login with root user this is not recomnded.
=========================================================
1) passwdauth----------means
we can login using passwd -----this need passwdauth=yes
syntax
ssh username@ip

2) passwdless auth
we can loginusing private key
syntax
ssh -i privatekey username@ip

3) we are using our key and login intothe machine


ssh-keygrn -generate 2 files
ssh-copyid -i .pu -p 2222 username@ip

ssh -i our privatekey username@ip

su--with in machine
ssh --locat to remote --means wewant that comd login into machine all auth done
then that screen connect to us

when ever login into machine wants user.


we login into server user with ssh .
====================================================
sudo yum install openssh-server

copy files from local machine to remote machine (or) from one machine to another
machine

syntax
scp also intranally using ssh cmd only
i want to copy files from one machine to remote machine using private-key
scp -i "privatefile" filename ubuntu@ip:/home/ubuntu

syntax
scp also intranally using ssh cmd only
i want to copy files from one machine to remote machine using using
passwdauthication
scp filename ubuntu@ip:/home/ubuntu
asking passwd.
it asking psw we can do /etc/ssh/sshd_config file change passwdauthication no to
yes

scp internally using ssh connection

ssh -i "privatekey" ubuntu@ip

cp : with in machine copy the files

cp file1 /abc/bbc
cp /self/f1 /bbc

scp -i "privatefile" ubuntu@ip:/home/ubunt/f1.txt .

using of passwd
syntax: scp ubuntu@ip:/home/ubuntu/f1 .

scp command login into passlessauth means it will check pub and private authication
it sucess
then thal local file copy into remotemachine location whet ever we give
when ever we are using scp command internally it will use ssh conn
means
ssh login into that machone using private key local file copy into remote machine
loaction

scp command login into passlessauth means it will check pub and private authication
it sucess
then thal local file copy into remotemachine location whet ever we give
===================================================================================
=
copy file we required
1) ip
2) login means(user)
3) passwdless so private key
4)dest location
5) what do you want to copy that file

=================================================
connect to aws ec2-1 to ec2-2
step 1) luanch ec2 instancess
2) login
3) from ec2-instance-1 to connect ec2-2
4) i want to connect to ec2-2 using two ways 1) passwd 2) passwdless
5)using passwd----change passwdauth no to yes
syntax
ssh user@ip
6) using passwdless auth i want private key but that private in my local machine
i want to private key file sent to ec2-1 then using of that login into server user
syntax for copy private file to ec2-1
scp privatefile user@ip:/home/
syntax:
for connect to ec2-2
ssh -i privatekey user@ip--asking passwd
why means we are using su also it is asking passwd so we use sudo su
sudo ssh -i privatekey user@ip--asking passwd
========================================================================
ssh-keygen --downlaod 2 keypairs
ssh-copy-id -i ----------it is using internal ssh
scp ---it is using internally ssh
su---swithch user with in server
ssh -i ----it login into your server using of username+ip ---keypair or passed that
output connect to on gitbash
=================================================================================
SSH
scp
su
/etc/ssh/sshd_config
ssh-copy-id
ssh-keygen: default name of key-pair is id_rsa.pub,id_rsa
default loc of key-pairs is ~/.ssh/auth_keys
=================================================================
vi
i/a
esc
:w
:q
=================================================================
1) create new dir in your local machine
2) create public key and private key
3) luanch ubuntu ec2-insance
4) create sheshi
5) reset sheshi user passwd and notedown
6) change the passwd auth no to yes
7)change ssh port number 2222
8)restart ssh service
9) exit from instance
10) copy local publick key into sheshi user
11) try to login to server using sheshi user, using private key

-p 2222

ssh-keygen------oct20.pem,oct20.pub
ssh-copy-id -i oct20.pub -p 2222 sheshi@ip
passwd: -------
ssh -p 2222 sheshi@ip-----login
create user an reset passwd done by only admin only
create user: useradd -m -s /shell/bash sheshi
rest passw: passwd sheshi
===============================================================
scp -P 2222 oct20.pub sheshi@44.193.16.147:/home/
sheshi@44.193.16.147's password:
oct20.pub
in scp we are using captial P -P

.ssh file created in userhome dir we dont have userhome dir that .ssh file
is not created
.ssh file created we are trying copy .pub data
==========================================
first we giving .pem file that is 1st preferance it is not match it will
ask passwd

ssh-copy-id -i key1.pub -p 2222 sheshi@ip

ssh-copy-id -i key2.pub -p 2222 sheshi@ip

ssh -i key1.pem -p 2222 sheshi@ip --- it does not prompt passwd if


passwdauth yes also. it trying to login using private key

private key having 400 permision other wise all are excuting private key
so persmsions must 400 on private-key.

============================
login into server user required
ip
user
privatekey or passwd
port

==========================================================

1) luanch ubuntu ec2-instance name it as i1

2) luanch ubuntu ec2-instance name it as i2


3) login into i2
4) create user sheshi
5)create sheshi user passwd and note down
6) allow passwd auth no to yes on i2
7) exit from i2
8) create new sshkeys in your local machine
9) copy public key file into ec2-2 sheshi user
10) copy private key file into i1
11) from i1 connect to i2 in sheshi user by using private key
12) exit from i2
13) create new keys inside i1
14) create copy public key into i2 sheshi user
15) delete public key from i1
16) login into i2 sheshi user using step13 privatekey
17) exit from i2
18) create dir, name it as mydir
19) create files inside f1,f2,f3
20)copy mydir into i2/home/ubuntu using sheshi user private
scp -r mydir sheshi4@44.193.16.147:/home/ubuntu
-r we want to use recursive and on ubuntu dir having write permsion to sheshi user
other wise it will throws error permsion denied
21) download /etc/passwd from i2 to i1 /tmp dir

scp sheshi@ip:/etc/passwd /tmp


==============================================
useradd---->/etc/passwd /etc/group ---when ever we create users that 2 files some
chsnges done
passwd-----/etc/shadow ----when ever create userpasswd this file some changes
id--it will give curent user info
is sheshi
ssh-copy-id & scp-both are copy files from one machine to another machine
ssh-keygen----generate our own key-pairs
ssh----using this command we can login into remote machine user by default port 22
config files are located in /etc/ssh
when ssh config files chang need to restart using service ssh restart
su -- with in a server one user to another user passwd mandatort
su we not mention it will go to root user

passwd cmd by default change passwd of curent user


sudo passwd --it changing passwd to root user because intenally using that cmnd
root only
so root user curent user so that cmnd changes root user passwd.
=============================================
how do you know passwd is locked or unlock

passwd file /etc/shadow file that user having !dhjdshjdshjdh starting with (!)
so that user is passwd locked but passwd is avaliable

how to lock passwd


passwd -l ubuntu - -- iam lock the passwd of ubuntu
ubuntu passwd info starting with !

how to lock passwd


passwd -u ubuntu

grep ^ubuntu /etc/shadow


=============================
======================================================

You might also like