Wednesday 6 February 2019

AWS EC2 Machine

Remote access with key pairs
First step: 
Local machine generate public key: 
test -f ~/.ssh/id_rsa.pub && cat ~/.ssh/id_rsa.pub || 
ssh-keygen -t rsa -C "my@example.com" && cat ~/.ssh/id_rsa.pub
Save key without any formatting
Second step:
Create a new account and add the newly created account to the sudo(admin) group:
- useradd user_name -m -s /bin/bash -c 'admin user' && usermod -aG sudo user_name
Let users who are in sudo group no need to enter password when switching to root:
visudo
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
Then, shift user to new user
# sudo su - user_name
Last step: put local public key to remote’s account:
steven2@remote $ mkdir ~/.ssh \
&& chmod 700 ~/.ssh \
&& touch ~/.ssh/authorized_keys \
&& chmod 600 ~/.ssh/authorized_keys \
&& vim ~/.ssh/authorized_keys
ctrl+ins command to paste the public key from local machine
esc + : + w
esc + : + q
Then, locally start connection: 
mosh user_name@public_dns

No comments:

Post a Comment