Skip to content

Instantly share code, notes, and snippets.

@radityaarya
Created September 27, 2017 11:05
Show Gist options
  • Save radityaarya/752cc5516548632037d1a658381a1a75 to your computer and use it in GitHub Desktop.
Save radityaarya/752cc5516548632037d1a658381a1a75 to your computer and use it in GitHub Desktop.
# Setting Up VPS
- accessing server
command:
$ ssh -i /pem/location/ [email protected]
example :
$ ssh -i ~/.ssh/pem/mypem.pem [email protected]
note :
- save pem in ~/.ssh/pem/
- create user (if needed)
command :
$ sudo adduser newuser
note :
- follow the instructions
- one of the instructions may ask you to create password
- add user as sudoers
command :
$ sudo usermod -aG sudo newuser
then try to access newuser :
$ su - newuser
> your console location should be changed to '[email protected]'
then try to list '/root' directory :
$ sudo ls -al /root
loging out from [email protected]
ctrl + D
- set locale
command :
$ sudo locale-gen en_US
$ sudo nano /etc/environment
add :
LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8
then save.
- install bash-completion, nano, xclip, and vim.
command :
$ sudo apt-get install bash-completion nano xclip vim
- install git
command :
$ sudo apt-get install git-core curl build-essential openssl libssl-dev libxslt-dev libxml2-dev libcurl3-dev
- ssh key
WARNING :
— make sure you are in the right user. In this case, we will generate ssh for newuser that we just created before.
— if you are not in newuser :
$ su - newuser
Generate shh :
$ ssh-keygen -t rsa -C 4096
> will show you this message :
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
> type location or enter for choose default location. next :
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
> ssh will be generated with something like this :
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:LBKSJANDdH2c05MSvk+tOTf8zR316iAG1yvqyvE root@ip-172-30-0-180
The key's randomart image is:
+---[RSA 2048]----+
| oO=.+o ..+ . |
| +o...o..* + |
| .+ . ..o . |
| . . o o . |
| . S o o . .|
| . o o = o|
| . + B +..|
| . o o o + =+|
| ooE .o =|
+----[SHA256]-----+
check your ssh_id :
$ cat ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa
those command will show your id_rsa.
note :
- '4096' in 'ssh-keygen -t rsa -C 4096' means the key size we are choosing. read more : https://www.ssh.com/ssh/keygen/#sec-Choosing-an-Algorithm-and-Key-Size
- id_rsa is private key. id_rsa.pub is public key. make sure you ONLY share the public one.
Add your local-key to remote server (use multiple terminal tab)
on server ([email protected]):
$ cd ~/.ssh
$ touch authorized_keys
on local :
$ cat ~/.ssh/id_rsa.pub
copy the shown key
back to server ([email protected]) :
$ cd ~/.ssh
$ echo 'paste-your-local-key-here' >> authorized_keys
check :
cat ~/.ssh/authorized_keys
then try to access 'newuser' through your local console :
warning! Make sure your console in local position!
$ ssh [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment