How To Use A Socket Created By Root With A Normal User
So I have this server:
import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.bind('/tmp/sock.sock') sock.listen(1) while True: conn, ca = sock.accept() print(conn.recv(1024))
And this client:
import socket sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock.connect('/tmp/sock.sock') sock.send('Hello, World')
The actual sending and receiving is a bit more complex, but works perfectly, as long as both the server and client is run by root. It also works when the client is run as root and the server is run by a normal user. But when I try to run the server with root and client by normal user I get this:
$ python3 client.py connecting to /tmp/sock.sock [Errno 13] Permission denied
How can I solve this? The server need to be run as root and the client as an unprivileged user.
I have understood as much as that it has to do with file permissions for the socket file, but I cannot see how I should fix it. I could not see any options to pass to the socket constructor that would fix this.
Change file mode to allow anyone to access it. Add this lines in your server
import os os.chmod("/tmp/sock.sock", 0o777)
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module