7

There are lots of different python versions in my ubuntu machine:

/home$ ls /usr/bin/ | grep python
dh_python2
dh_python3
python
python2
python2.7
python3
python3.5
python3.5m
python3m

/home$ which python
/usr/local/bin/python

python --version
Python 3.6.6

I want a certain user group have access to only "python"(e.g. 3.6.6) and disable access for other versions.

I think uninstalling python would cause other problems.What would be the recommended way to achieve this goal without breaking anything?

2
  • If you look at the real files and their size, you only have 3 version: 2.7, 3.5 and 3.5m (which is 3.5 with a different memory allocation scheme).
    – xenoid
    Sep 27, 2018 at 13:19
  • @xenoid, yes those came with ubuntu. There is also another one which I installed(3.6.6 version) and I want the users to use that new version and have no access to older versions.
    – Caner
    Sep 27, 2018 at 13:21

3 Answers 3

3

chown the non-public version(s) to a specif group, make it executable only by that group (chmod 754 ...), and add the allowed users to that group.

But keep in mind that there are system utilities that rely on specific python versions, so you will likely break something: in my Ubuntu 16.04, /usr/bin contains 106 files with a python.* shebang, of which 47 have a python3 shebang.

2
+25

I want the users to use that new version and have no access to older versions.

Don't.

There's a reason Ubuntu comes with two versions of Python. It's that some utilities are written in Python2, and can not run in Python 3. Others are written in Python 3, and can not run in Python 2.

In addition Python 2 is still widely used for all kinds of tasks, and the majority of Python code out there is probably still Python 2.

Python 2.7 will be supported with bug fixes until at least 2020.

2

I did this by using the acl permissions. I just removed access to wrong python versions for my target user group. simple as that, nothing is broken(can't believe anyone suggested this).

Install acl

sudo apt-get install acl

Remount system disk with acl support

Edit fstab:

sudo nano /etc/fstab

Add "acl" support if not there already, for example changing from

UUID=abc-123-456-789 / ext4 defaults 1 1

To:

UUID=abc-123-456-789 / ext4 defaults,acl 1 1

Remount the root:

sudo mount -o remount /

Set access rights

Create symbolic link for python3 so that both python and python3 works for my target user group:

sudo ln -s /usr/local/bin/python /usr/local/bin/python3

Update acl permissions so that access is removed from system python versions for user group "blocked":

setfacl -m g:blocked:- -R /usr/bin/python2
setfacl -m g:blocked:- -R /usr/bin/python3
setfacl -m g:blocked:- -R /usr/bin/python3.5m

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.