Last active
June 9, 2019 09:34
-
-
Save daniil4udo/ff1a44ca17dd4250dbe9506ffad90de2 to your computer and use it in GitHub Desktop.
SSH Snippets to login to the server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SSH Cheat Sheet | |
# Create folder, file, install Apache (Just messing around) | |
mkdir test | |
cd test | |
# Create hello.txt file | |
touch hello.txt | |
# Install Apache server | |
sudo apt-get install apache2 | |
# Generate Keys (Local Machine) | |
ssh-keygen | |
# See content of the key folder | |
ls .ssh | |
# See content of the public key | |
cat .ssh/id_rsa.pub | |
# Now need to put public key on the server | |
# If have brew (macOS) use | |
brew install ssh-copy-id | |
# Alternative. Add Key to server in one command | |
#cat ~/.ssh/id_rsa.pub | ssh daniil@192.168.1.29 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys | |
# Create & copy a file to the server using SCP | |
touch test.txt | |
# Put in the home folder in the server | |
scp ~/test.txt daniil@192.168.1.29:~ | |
# Login via SSH without the password (LOCAL SERVER) | |
ssh daniil@192.168.1.29 | |
# DIGITAL OCEAN | |
# Create Keys For Droplet (i.e. id_rsa_do, but you can choose different name. DO stands for Digital Ocean) | |
ssh-keygen -t rsa | |
## Create account->create droplet | |
## Add Key When Creating Droplet | |
# Try logging in | |
ssh root@SERVERS_IP_ADDRESS | |
# If it doesn't work, add your key, using the name you've choose during creation | |
ssh-add ~/.ssh/id_rsa_do | |
# Login should now work | |
ssh root@SERVERS_IP_ADDRESS | |
# Update packages | |
sudo apt update | |
sudo apt upgrade | |
# Create new user with sudo, never use root user, to prevent bruteforce etc. | |
adduser daniil | |
# Just user without the priviliges | |
id daniil | |
# Add priviliges | |
usermod -aG sudo daniil | |
# Now user with the priviliges | |
id daniil | |
# Login as daniil, wont work -> PERMISION DENIED | |
ssh daniil@SERVERS_IP_ADDRESS | |
# We need to add the key to daniils .ssh on the server, log back in as root | |
ssh root@SERVERS_IP_ADDRESS | |
cd /home/daniil | |
mkdir .ssh | |
cd .ssh | |
touch authorized_keys | |
# Paste in the id_rsa_do.pub key, exit and log in as daniil | |
sudo nano authorized_keys | |
# Now exit the root and login with newly created user name | |
exit | |
ssh daniil@SERVERS_IP_ADDRESS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment