View on GitHub

my-linux-scripts

Some basic setup steps, when setting up a clean Debian or Ubuntu VPS server, from a linux distribution

SSH ACCESS SETUP

Open up you terminal “CTRL + ALT + T”.

mkdir -p ~/.ssh/
cd ~/.ssh/

Generate 1 private and 1 public key for you ssh connection:

ssh-keygen -t rsa -b 4096
# -> Enter data for the keypair (name + password)

After these steps your new key pair is generated in the current directory.

Print out the public key file’s contents and the select the contents in your terminal and copy them. (you could also open it in an editor and copy the contents there, or use xclip to do this inside of the terminal)

cat key_name.pub

Insert as ssh public key on your hosters side if that option is available. (probably the best and securest option) If not your hoster might provide you with a login password to your root account, then you can omit setting the
-i (identityfile) option in the next terminal step. (TODO add description for how to add pub key files manually)

Then find out the public ip of you server from your hoster (your.public.ip.address)
Usually findable somewhere on your dashboard or in your server settings/info


Ssh into your server as root user (to take control over it), with the info from your hoster.

ssh root@your.public.ip.address -i ~/ssh/key_name

Now you can use the server as you would an normal ubuntu/debian machine from the terminal and continue to the next section.

INITIAL USER SETUP

passwd


cat /etc/sudoers


adduser yournewusername

Then enter your new Password for the user and other user info in the prompts that follow.


usermod -G sudo yournewusername

Yay now your user “yournewusername” can use “sudo”


su yournewusername


sudo -v

Should print out nothing.
If you do not have sudo priviledges “Sorry, user testuser may not run sudo on machine” is printed.

You could also print out sudoers to check if your user is in the list:

cat /etc/sudoers


sudo nano /etc/ssh/sshd_config
  1. -> Go to
    PermitRootLogin yes
  2. and set it to PermitRootLogin no
  3. Save:ctrl + x -> y -> ,Enter


sudo systemctl restart sshd


exit


ssh root@your.public.ip.address -i ~/ssh/key_name

If you enter your correct root password and it says “Permission denied, please try again” it worked.


ssh yournewusername@your.public.ip.address -i ~/ssh/key_name

After entering your password you should be able to access the server using your new user

Configuring a SSH-shortcut to speed up and simplify the ssh connection process

To permanently save your ssh logon info you can use the config file.


touch ~/.ssh/config
nano ~/.ssh/config


Host myserver
	HostName your.public.ip.address
	User pmarkus
	PORT 22
	IdentityFile ~/.ssh/hostinger_rsa


If you like the article consider dropping me a coffee

paypal