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 许可协议。转载请注明出处!
相关文章
Linux编译安装Python3-6,理论上各个发行版通用
前言 最近笔者把一个django项目部署到一个新的服务器上,而这个服务器给的是CentOS6版本的系统,官方源很旧,还被运维把源搞坏了,没办法通过源安装Python3.6以及pip,所以只好用最原始的方法,编译安装! 注意 如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,不要动现有的python2环境! 官网下载的
2022-06-17 · Linux · 约 1 分钟
你可能不知道的Linux死机重启方法
前言 不管在工作或者学习中,都可能遇到电脑死机的情况,如果直接强制关机或者切断电源可能会带来硬件的损坏,严重的可能导致数据丢失。 在学习中使用Linux经常遇到死机的情况,而且无法通过Alt+Ctrl+F[1-7]登陆,也无法通过ssh登陆。 更安全、底层的方法 按下Alt+Ctrl+SysReq(PrintScr键)一秒钟,保持Alt+Ctrl按下状态,松开PrintScr键; 保持按下Alt+
2022-06-17 · Linux · 约 1 分钟
SSH 跳板机原理与配置:实现无缝跳板连接,一步直达目标主机
在日常运维或开发工作中,我们常常需要访问部署在内网的服务器。然而出于安全策略或网络拓扑的限制,内网服务器并不会直接向外部暴露端口,导致我们无法“直连”它们。此时,**跳板机**(Jump Host/Bastion Host)就成了必不可少的中转
2025-01-17 · Linux · 约 1 分钟
经历分享,发现挖矿木马后,服务器快速备份与重装(腾讯云平台)
服务器又中木马?备份重装一套走起,coscli搞定。一键脚本压缩上传,硬盘镜像SSH传输,安全加固到位。AI时代更需小心,重装系统省心省力。
2026-03-04 · Linux · 约 1 分钟
讨论
共 0 条加载评论中…