Difference between revisions of "Access server"

From Anarchaserver
Line 31: Line 31:
Select the public key, and copy it to your clipboard or send it by email.
Select the public key, and copy it to your clipboard or send it by email.


=== creating super user accounts ===
=== creating new sysadmin accounts ===
Changing to root user
Changing to root user
su root
$ su root


we create superuser (note: it will ask me to introduce a passwd)
we create superuser  
adduser superusername
$ adduser superusername
then we will add the superuser to sudoers:
add the superuser to the group sudoers:
gpasswd -a superusername sudo
$ sudo addgroup (username) sudoers
 
we now change to superuser:
su superuser
 
 
When we change user, we will be by default in the  user's home directory (~). You can do "cd ~" just in case.
 
 


=== creating .ssh directory and authorized_keys document in the superuser home directory ===
=== creating .ssh directory and authorized_keys document in the superuser home directory ===

Revision as of 21:59, 13 August 2015

SSH

SSH keys provide **a more secure way** of logging into a virtual private server with SSH than using a password alone. Generating a key pair provides you with two long string of characters: a public and a private key. You can place the public key on the server, and then unlock it by connecting to it with a client that already has the private key. When the two match up, the system unlocks without the need for a password. You can increase security even more by protecting the private key with a passphrase.

Create RSA Key Pair

You create your rsa key pair in the computer you want to log to the server

Be careful to pay attention from which user you create the rsa key pair in your local machine (computer). Since the rsa key pairs are saved in a hidden directory in my user home directory (~/.ssh), if trying to login from a different user, it will not work

So, from the user in my localmachine that I wish to use to access the server, I will create my rsa key pair. When generating the key, you will need to introduce a **"passphrase".**


$ ssh-keygen

By default it will generate two keys in ~/.ssh, a public key and a private key. The public key we will send to an admin of Anarcha server.

Send public key to the server

After generating an SSH key pair, you will want to copy your public key to your new server.

Assuming you generated an SSH key pair using the previous step, use the following command at the terminal of your local machine to print your public key (id_rsa.pub):

**cat ~/.ssh/id_rsa.pub**

This should print your public SSH key, which should look something like the following:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBGTO0tsVejssuaYR5R3Y/i73SppJAhme1dH7W2c47d4gOqB4izP0+fRLfvbz/tnXFz4iOP/H6eCV05hqUhF+KYRxt9Y8tVMrpDZR2l75o6+xSbUOMu6xN+uVF0T9XzKcxmzTmnV7Na5up3QM3DoSRYX/EP3utr2+zAqpJIfKPLdA74w7g56oYWI9blpnpzxkEd3edVJOivUkpZ4JoenWManvIaSdMTJXMy3MtlQhva+j9CgguyVbUkdzK9KKEuah+pFZvaugtebsU+bllPTB0nlXGIJk98Ie9ZtxuY3nCKneB+KjKiXrAvXUPCI9mWkYS/1rggpFmu3HbXBnWSUdf localuser@machine.local

Select the public key, and copy it to your clipboard or send it by email.

creating new sysadmin accounts

Changing to root user $ su root

we create superuser $ adduser superusername

add the superuser to the group sudoers: $ sudo addgroup (username) sudoers

creating .ssh directory and authorized_keys document in the superuser home directory

As the superuser to whom we want to give ssh access to the server, create a new directory called .ssh and restrict its permissions with the following commands:

**mkdir .ssh** **chmod 700 .ssh**

       chown superuser:group

Now open a file in .ssh called authorized_keys with a text editor. We will use nano to edit the file:

**nano .ssh/authorized_keys**

Now copy-paste the public key (which should be in your clipboard) by pasting it into the editor.

Save and close.

Now restrict the permissions of the authorized_keys file with this command:

**chmod 600 .ssh/authorized_keys**

       chown superuser:group

Type this command once to return to the root user:

exit

Now you may SSH login as your new user, using the private key as authentication.


SSH Reverse DNS Lookup Disable

The invalid logins are normal, since there are bots that try to bruteforce servers.

As for the "possible break-in attempt" message, The system is trying to do a reverse DNS lookup to match the connecting IP with the hostname that is trying to connect and fails to do so.

The setting that controls that is "UseDNS" in /etc/ssh/sshd_config

sudo nano /etc/ssh/sshd_config

y agrega la línea:

UseDNS no


sudo /etc/init.d/ssh restart


Force ssh login to server

**sudo nano /etc/ssh/sshd_config**

and change:

ChallengeResponseAuthentication no PasswordAuthentication no UsePAM yes


sudo /etc/init.d/ssh restart


Change ssh port access

sudo nano /etc/ssh/sshd_config

The first option that you may want to change is the port that SSH runs on. Find the line that looks like this:

Port 22

If we change this number to something in **between 1025 and 65536**, the SSH service on our server will look for connections on a different port. This is sometimes helpful because unauthorized users sometimes try to break into servers by attacking SSH. If you change the location, they will need to complete the extra step of sniffing it out.

If you change this value, you will need to keep in mind that your server is running on the new port.


    • service ssh restart**

So now you would have to access to the server like this:

ssh superuser@server -p portnumber


References

http://ubuntuforums.org/showthread.php?t=1773227

http://bodhizazen.net/Tutorials/SSH_security