SocketException: Permission denied on Ubuntu 18.04 with default ports
See original GitHub issueDescribe the bug
When starting .Net Core 2.2 application On freshly installed and patched Ubuntu 18.04 Linux As an unprivileged linux user With both TCP and TLS default ports configured Application crashes with:
Unhandled Exception: System.Net.Sockets.SocketException: Permission denied
Which project is your bug related to?
- MQTTnet.Server standalone
To Reproduce
Steps to reproduce the behavior:
- Using this version of MQTTnet ‘3.0.5’.
- Run this code ‘See code below’.
- With these arguments ‘dotnet run’.
- See error.
Expected behavior
Application starts up correctly.
Screenshots
Not applicable.
Additional context / logging
mqtt@Ubuntu18.04:~/mqtt_server$ dotnet run
Environment: Development
Unhandled Exception: System.Net.Sockets.SocketException: Permission denied
at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName)
at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue, Boolean silent)
at System.Net.Sockets.Socket.SetSocketOption(SocketOptionLevel optionLevel, SocketOptionName optionName, Int32 optionValue)
at MQTTnet.Implementations.MqttTcpServerListener.Start(Boolean treatErrorsAsWarning, CancellationToken cancellationToken)
at MQTTnet.Implementations.MqttTcpServerAdapter.RegisterListeners(MqttServerTcpEndpointBaseOptions options, X509Certificate2 tlsCertificate, CancellationToken cancellationToken)
at MQTTnet.Implementations.MqttTcpServerAdapter.StartAsync(IMqttServerOptions options)
at MQTTnet.Server.MqttServer.StartAsync(IMqttServerOptions options)
at mqtt_server.Program.Main() in /home/mqtt/iot/mqtt_server/Program.cs:line 58
at mqtt_server.Program.<Main>()
mqtt@Ubuntu18.04:~/mqtt_server$ strace -f -s 20 -e trace=%network dotnet run -c Debug
strace: Process 2451 attached
strace: Process 2452 attached
...
Environment: Development
strace: Process 2514 attached
strace: Process 2515 attached
strace: Process 2516 attached
strace: Process 2517 attached
strace: Process 2518 attached
strace: Process 2519 attached
[pid 2503] socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 100
[pid 2503] setsockopt(100, SOL_SOCKET, SO_DEBUG, [1], 4) = -1 EACCES (Permission denied)
Unhandled Exception: System.Net.Sockets.SocketException: Permission denied
...
Code example
var certificate = new X509Certificate2(@"certificate.pfx", "[REDACTED]", X509KeyStorageFlags.Exportable);
var optionsBuilder = new MqttServerOptionsBuilder()
.WithDefaultEndpointPort(1883)
.WithEncryptedEndpoint()
.WithEncryptedEndpointPort(1884)
.WithEncryptionCertificate(certificate.Export(X509ContentType.Pfx))
.WithEncryptionSslProtocol(SslProtocols.Tls12)
.WithPersistentSessions()
.WithConnectionBacklog(100)
.WithApplicationMessageInterceptor(async context => {
// handler code
}
})
.WithMaxPendingMessagesPerClient(3)
.WithConnectionBacklog(100)
.WithStorage(new RetainedMessageHandler())
.WithDefaultCommunicationTimeout(TimeSpan.FromMinutes(5))
;
var mqttServer = new MqttFactory().CreateMqttServer();
await mqttServer.StartAsync(optionsBuilder.Build());
...
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
SocketException: Permission denied on Ubuntu 18.04 with ...
SocketException: Permission denied on Ubuntu 18.04 with default ports #720 ... With both TCP and TLS default ports configured
Read more >Tomcat7 won't start up on ubuntu (clean install), permission ...
I have installed it via terminal, run the "sudo service tomcat7 start" command which should start tomcat, but when I try to open:...
Read more >Listening error on port 80 when nothing else is using it
I'm migrating my webserver from my Windows laptop over to another computer running Ubuntu 18.04 server. The program I'm using is Abyss Web ......
Read more >Ubuntu + Jetty: Permission required for service using port ...
I am trying to run jetty as a service on ubuntu 16.04 on port 8010. It fails with a SocketException: Permission denied.
Read more >How to run a server on port 80 as a normal user on Linux?
Short answer: you can't. Ports below 1024 can be opened only by root. As per comment - well, you can, using CAP_NET_BIND_SERVICE, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I will release the new version this weekend.
@chkr1011, is there a timeline or ETA for 3.0.6?