To log into your server, you will need to know your server’s public IP address. You will also need the password or the private key for the root user’s account if you installed an SSH key for authentication.
ssh root@your_server_ip
Once you log in as root, you’ll be able to add the new user account. In the future, we’ll log in with this new account instead of root. This example creates a new user called unuser, but you should replace that with a username that you like:
adduser unuser
usermod -aG sudo unuser
ufw app list
OutputAvailable applications:OpenSSH
You will need to make sure that the firewall allows SSH connections so that you can log into your server next time. Allow these connections by typing:
ufw allow OpenSSH
Now enable the firewall by typing:
ufw enable
Type y and press ENTER to proceed. You can see that SSH connections are still allowed by typing:
ufw status
OutputStatus: activeTo Action From-- ------ ----OpenSSH ALLOW AnywhereOpenSSH (v6) ALLOW Anywhere (v6)
ssh unuser@your_server_ip
Note: The rsync command treats sources and destinations that end with a trailing slash differently than those without a trailing slash. When using rsync below, ensure that the source directory (~/.ssh) does not include a trailing slash (check to make sure you are not using ~/.ssh/).
If you accidentally add a trailing slash to the command, rsync will copy the contents of the root account’s ~/.ssh directory to the sudo user’s home directory instead of copying the entire ~/.ssh directory structure. The files will be in the wrong location and SSH will not be able to find and use them.
rsync --archive --chown=unuser:unuser ~/.ssh /home/unuser