大网数据广告活动
服务器运维问答

Mount folder automatically in home directory for every old&new user

· 52CE 我爱测

I want to allow access to /var/www/dev/ to every user in my system (+50) via their home directory For one particular user I can do: mkdir /home/user_name/www_dev mount --bind /var/www/dev/ /home/user_name/www_dev And then make th…

问题原文

原帖链接 · berriop · CC BY-SA 3.0

I want to allow access to /var/www/dev/ to every user in my system (+50) via their home directory

For one particular user I can do:

mkdir /home/user_name/www_dev mount --bind /var/www/dev/ /home/user_name/www_dev

And then make this configuration permanent by editing /etc/fstab:

/var/www/dev /home/user_name/www_dev none bind 0 0

My question is: the above is for 1 particular user, how can I make this work for every user in the system? and automatically when I create a new user?

已采纳解答

原帖链接 · Mike Marseglia · CC BY-SA 3.0

I would use a symlink instead of mount. You can accomplish this easily by creating a file in /etc/profile.d. In the file add the command to create the symlink. Since the scripts in /etc/profile.d run as the user, the command would be:

ln -fs /var/www/dev ~/www_dev

Using the system wide profile will ensure the symlink is created even if the user removes it.

This will only work if the user is using an interactive login shell, e.g. ssh or su. See https://askubuntu.com/questions/438150/scripts-in-etc-profile-d-being-ignored for more information on types of login shells and startup scripts.

For more information on how /etc/profile.d works see https://unix.stackexchange.com/questions/64258/what-do-the-scripts-in-etc-profile-d-do

Another way to do this is to use the useradd command and make use of /etc/skel. http://linux.die.net/man/8/useradd

When using useradd, anything in the /etc/skel directory gets copied to the new user's home directory. You could place a symlink in /etc/skel using the source's absolute path and destination's relative path.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。