云服务器入门第一步
正文
Step 2 - Creating a New User
adduser user_name
You will be asked a few questions, starting with the account password.
Enter a strong password and, optionally, fill in any additional information you would like. This information is not required, and you can press ENTER in any field you wish to skip.
Step 3 - Granting Administrative Privileges
usermod -aG sudo user_name
命令和参数解释 ....
Step 4 - Setting Up a Firewall
You can examine the list of installed UFW profiles by typing:
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
ufw status
OutputStatus: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Step 5 - Enabling External Access for Your Regular User
Note: 在确保regular user能够正常登录并且能够使用sudo命令之前, 最好保持root账号的登录
Uses SSH Key Authentication
add a copy of your local public key to your new user’s ~/.ssh/authorized_keys file.
Since your public key is already in the root account’s ~/.ssh/authorized_keys file on the server, you can copy that file and directory structure to your new user account using your current session.
rsync copy note:
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=sammy:sammy ~/.ssh /home/sammy
命令和参数解释 ....
enable之后记得先开一个terminal测试新用户的ssh连接和sudo命令再关掉root