Configuring a Linux environment for the team: a simple and efficient project sharing solution.
Setting up a Linux multi-user shared environment? Just configure group permissions and SGID settings. Use SSH public key authentication, share a conda environment, and copy progress with rsync. These operations are simple and efficient, but why go through all that hassle?
目录13 个章节
Preface
It's been a while since I last wrote a blog post—things have been incredibly busy lately. I've also started a fun new project; once it's further along, I'll write an article to introduce it.
In our current AI project, the team needs to share a GPU server for model training and data processing. To ensure every team member can use the server efficiently, we decided to set up a shared multi-user environment. This way, whether it's code development, model testing, or result verification, everyone can conveniently access and leverage the server's powerful computing resources.
This article will document the process of configuring the Linux shared environment, and hopefully, it will also help other teams facing similar needs.
Setting Up Users and Groups
To efficiently manage our GPU server, we first need to create new user accounts and organize these accounts into a dedicated user group. This approach simplifies permission management and access control.
Creating Users and Groups
First, create a group
sudo groupadd gpugroup
Next, create a user
sudo adduser [username]
Then add the user to the group
sudo usermod -a -G gpugroup username
Configuring SSH Public Key Login
To enable team members to securely connect to the server via SSH, public key authentication should be used uniformly, with password login prohibited.
Each user needs to generate a key pair (if they haven't already) and send the public key to the administrator. Then, the administrator needs to add these public keys to the user's .ssh/authorized_keys file.
First, ensure that each user's home directory has a .ssh directory. If it doesn't exist, you can create it using the following command:
sudo mkdir /home/[username]/.ssh
sudo chmod 700 /home/[username]/.ssh
Next, add the public key to the authorized_keys file:
echo [public key content] >> /home/[username]/.ssh/authorized_keys
sudo chmod 600 /home/[username]/.ssh/authorized_keys
Replace [username] and [public key content] with the actual username and public key.
Creating a Shared Folder
Previously, I stored my code in the home directory. However, in practice, I found this to be unfavorable for sharing.
After all, designating a folder under a user's home directory as a shared directory for other users to access always feels a bit odd.
Typically, for better security and organization, it is preferable to create a dedicated directory for shared projects. I consulted GPT, and here's what it advised:
Security: Avoid unnecessary permission exposure. When you place projects within a personal home directory, you might inadvertently grant other users excessive access rights, which could lead to sensitive information leaks or accidental data corruption.
Manageability: A dedicated shared directory makes management more straightforward. You can easily control who has access to this directory without worrying about affecting other personal data or settings.
Scalability: As the team grows, more users may need access to these shared resources. Having an independent shared directory simplifies managing users and permissions, instead of constantly adjusting permission settings under the home directory.
Clear Permission Demarcation: An independent shared directory makes setting and adjusting permissions clearer and simpler. For instance, you can apply customized security policies and backup strategies specifically for this directory.
Therefore, I created a directory /srv/projects under the /srv directory to use for sharing.
Group Permission Settings
Next, set the ownership of the team-shared project folder /srv/projects to the gpugroup group.
sudo chown -R root:gpugroup /srv/projects
sudo chmod -R 775 /srv/projects
Setting the SGID (Set Group ID)
SGID is a special permission setting that ensures any new file or directory created within a directory automatically inherits that directory's group. This is ideal for our project directory because it allows all team members to access and modify files without worrying about individual file group settings.
You can use the following command to set the SGID bit:
sudo chmod g+s /path/to/directory
For example, if our project directory is /srv/projects, the command would be:
sudo chmod g+s /srv/projects
With this setting, all new files and directories created under /srv/projects will automatically be assigned to the group, maintaining consistent permissions.
Adjust umask (optional)
PS: I didn't set this, it's possible but not necessary
umask is a system setting that determines the default permissions for newly created files and directories. To ensure team members can edit each other's files, we need to set an appropriate umask value.
The usual umask value is 022, which means new files default to permissions 644 (user can read and write, group and others can read), and new directories default to permissions 755 (user can read, write, and execute; group and others can read and execute). For team collaboration, we can set the umask to 002, so new files have permissions 664 (user and group can read and write, others can read) and new directories have permissions 775 (user and group can read, write, and execute; others can read and execute).
You can temporarily change the umask value with the following command:
umask 002
For permanent changes, you need to set it in the user's shell configuration file, such as .bashrc or .profile:
echo "umask 002" >> ~/.bashrc
Other Notes
There are some additional details. For example, I previously installed conda in the home directory.
Now I need to reinstall it in /srv/apps, and the original installation in home is no longer needed.
This way, all users can share Python virtual environments.
Displaying Progress When Copying Files
The cp -R command does not support displaying progress.
You can use rsync or pv as alternatives.
rsync
rsync -ah --progress source destination
Parameter Explanation:
-ais archive mode, which preserves symbolic links, file permissions, user group information, etc.-hmakes the output easier to read by using a human-readable format.--progressdisplays the copy progress.
pv
This is used in conjunction with compression tools and may not be pre-installed on some systems, requiring installation first.
tar cf - source/ | pv | tar xf - -C destination
This command archives the source directory and uses pv to display progress, then unpacks it in the destination directory.
Summary
This setup is basically done.
I've also recently explored some project management tools and deployed MatterMost.
Next, I can write articles to document this.
_EOF_
Configuring a Linux environment for the team: a simple and efficient project sharing solution.
- 本文作者:
- 程序设计实验室
- 版权声明:
- 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
相关文章
Manjaro-安装docker笔记
Manjaro的官方源里面就有docker,直接安装就行。 sudo pacman -S docker 启用docker服务 sudo systemctl start docker 设置开机自启动 sudo systemctl enable docker 这样安装的docker默认是只有root用户才能用,我们需要把当前用户添加到docker用户组,才可以。 # 如果还没有 docker grou
2021-12-18 · Linux · 约 1 分钟
硬盘空间消失之谜:Linux 服务器存储排查与优化全过程
最近我发现服务器磁盘空间突然占用异常,经过排查,罪魁祸首竟然是 Docker 容器的日志文件!
2024-12-17 · Linux · 约 1 分钟
你可能不知道的Linux死机重启方法
前言 不管在工作或者学习中,都可能遇到电脑死机的情况,如果直接强制关机或者切断电源可能会带来硬件的损坏,严重的可能导致数据丢失。 在学习中使用Linux经常遇到死机的情况,而且无法通过Alt+Ctrl+F[1-7]登陆,也无法通过ssh登陆。 更安全、底层的方法 按下Alt+Ctrl+SysReq(PrintScr键)一秒钟,保持Alt+Ctrl按下状态,松开PrintScr键; 保持按下Alt+
2022-06-17 · Linux · 约 1 分钟
Config-Software-mirrors-source-for-OpenSuSE-42-3
I just wrote a shell file to finish it. # Disable the system source sudo zypper mr -da # Add aliyun mirrors sudo zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/leap/42.3/non-oss/ openSUS
2022-06-17 · Linux · 约 1 分钟
讨论
共 0 条加载评论中…