output
stringlengths
9
26.3k
input
stringlengths
26
29.8k
instruction
stringlengths
14
159
Is your AD user a member of many large AD groups? This is typically the case, usually suppressing the group members with the ignore_group_members option helps. Alternatively, checking the sssd logs if the machine is able to connect to AD DCs and is not e.g. timing out the connection is also a good thing to do.
My Fedora 26 (was 25 when installed/joined to AD) has a long timeout when I run sudo for my Active Directory user if I leave it alone for to long. Timeout is long. 25 seconds. I used strace (sudo strace -tt -o sudo_wait.strace sudo dnf update -y) to see if I could see what the system was doing for those 25 seconds, but it seem to be nothing: [...] 07:50:48.362655 poll([{fd=3, events=POLLIN}, {fd=7, events=POLLIN}], 2, -1) = 1 ([{fd=7, revents=POLLIN|POLLHUP}]) 07:50:48.367202 recvfrom(7, "", 8, MSG_WAITALL, NULL, NULL) = 0 07:50:48.367287 poll([{fd=3, events=POLLIN}], 1, -1) = ? ERESTART_RESTARTBLOCK (Interrupted by signal) 07:51:12.493581 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=29817, si_uid=0, si_status=0, si_utime=896, si_stime=124} --- 07:51:12.493646 write(4, "\21", 1) = 1 07:51:12.493717 rt_sigreturn({mask=[]}) = -1 EINTR (Interrupted system call) 07:51:12.493769 poll([{fd=3, events=POLLIN}], 1, -1) = 1 ([{fd=3, revents=POLLIN}]) 07:51:12.493820 read(3, "\21", 1) = 1 [...]It is probably not good that I use sudo to run both strace and dnf as I don't know which one of them is actually causing the delay. I joined the machine to AD by using instructions here (or eerily similar). If I run sudo again directly after waiting the 25 seconds there is no delay, but every morning when I try after not touching the machine for a few hours the delay is back. How can I figure out what the machine is waiting for? ow can I tweak how long credentials are cached? How can I tweak how long the timeout is? EDIT: Just found this on RedHat. Creating the /etc/sudo.conf as suggested did produce a debug log. Now I'll just have to wait for the delay to come back and then go through that log.
Sudo long wait for Active Directory user
The suggestion to delete the sssd cache was indeed correct. However, running sss_cache -Edid not help. I had to actually delete the relevant files with rm -rf /var/lib/sss/db/*
I have an administration node running LDAP and a login node which uses LDAP on the other node to authorize users. Users are able to log into the login node successfully. When I run getent passwd, on the admin node I get all the users, both those from /etc/passwd and LDAP. However, on the login node the LDAP users are missing. Both machines are running CentOS 7.9.2009 and both have an identical /etc/nsswitch.conf. The only non-trivial differences between the two version of /etc/sss/sssd.conf is that on the admin node ldap_access_order = filter,expireis set, whereas on the login node the setting is ldap_access_order = expirebut that seems to me irrelevant (the filter just contains a single non-root functional user which was only used when the system was set up). Where else should I be looking to work out what the difference is between the two systems?
'getent passwd' not showing LDAP users, athough users can log in
To enable creation of users home directories exec this command (as root): pam-auth-update --enable mkhomedirAbout not available AD - sssd support cache so for some time you will be able to login with cached credentials. In domain section of sssd.conf you can add something like to manage the time: cache_credentials = true account_cache_expiration = 7 entry_cache_timeout = 14400(default time for cache is 5400 seconds) And AFAIK sssd never create entries in /etc/passwd and /etc/shadow
I was able to successfully join my Ubuntu 18.04 machine into AD. For this I'm using SSSD and Kerberos. I can ssh into in using AD domain credentials. Everything is fine except that those domain users are not persistent. When a domain user enters a Windows machine, then a home directory is created automatically and the user is added into the users list. This allows the domain user to log into Windows even if there's no network connection. But on my Ubuntu machine no home directory is created and no users are added into /etc/shadow and /etc/passwd. It means that if AD was down or the network was down, then there's no way for the domain users to login. Where can I find information on how to configure this properly? What files I need to look into? Or maybe Linux's AD stack does not allow it?
Linux in Active Directory: Persistent users
Found the problem. The sssd configuration contains the line ldap_access_filter = (host=<hostname>.mydomain.org)where hostname is the local host name for each server. However, the second server wasn't referenced in the LDAP server, only the first one was. Adding an entry for the second server on the LDAP solved the issue.
There are two RHEL 8 servers which have been provisioned from the same template, with some manual fix and tweaking done manually on the first server only. They allow SSH user authentication via a remote LDAP server, and have been configured with authselect: authselect select sssd --forceThe first server works perfectly, while on the second one the SSH authentication fails. I'm looking to find the difference between them, because their LDAP, PAM, sssd, and nscd configs appear the same. EDIT 11/6: The nslcd daemon is inactive; it has the default config, identical on both servers.It is also worth noting that getent passwd correctly returns all LDAP users, but these users cannot login via SSH. The sshd config is the same, too. By reading the sssd logs, I found out that the first server calls (correctly) ldap_search_ext with [(&(uid=dr01)(objectclass=posixAccount)(&(uidNumber=*)(!(uidNumber=0))))][dc=mydomain,dc=org]while the second one uses (failing) the search [(&(uid=dr01)(objectclass=posixAccount)(uid=*)(&(uidNumber=*)(!(uidNumber=0))))][dc=mydomain,dc=org]So, on the second server the query includes an additional (uid=*). It also refers to BE_REQ_USER vs BE_REQ_INITGROUPS in the first search (see logs below). This returns zero results. So, I'd like to know where the call to ldap_search_ext is defined.Here is an excerpt of the logs from the first server: (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [dp_get_account_info_send] (0x0200): Got request for [0x3][BE_REQ_INITGROUPS][[emailprotected]] (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sss_domain_get_state] (0x1000): Domain mydomain.org is Active (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [dp_attach_req] (0x0400): DP Request [Initgroups #13]: New request. Flags [0x0001]. (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [dp_attach_req] (0x0400): Number of active DP request: 1 (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sss_domain_get_state] (0x1000): Domain mydomain.org is Active (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sdap_get_initgr_next_base] (0x0400): Searching for users with base [dc=mydomain,dc=org] (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x0400): calling ldap_search_ext with [(&(uid=dr01)(objectclass=posixAccount)(&(uidNumber=*)(!(uidNumber=0))))][dc=mydomain,dc=org]. (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [objectClass] (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [uid] (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [userPassword] (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [uidNumber] (Fri Jun 7 15:15:46 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [gidNumber] (...) (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_search_user_process] (0x0400): Search for users, returned 1 results.and the second one: (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [dp_get_account_info_send] (0x0200): Got request for [0x1][BE_REQ_USER][[emailprotected]] (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [dp_attach_req] (0x0400): DP Request [Account #8]: New request. Flags [0x0001]. (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [dp_attach_req] (0x0400): Number of active DP request: 1 (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sss_domain_get_state] (0x1000): Domain mydomain.org is Active (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_search_user_next_base] (0x0400): Searching for users with base [dc=mydomain,dc=org] (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x0400): calling ldap_search_ext with [(&(uid=dr01)(objectclass=posixAccount)(uid=*)(&(uidNumber=*)(!(uidNumber=0))))][dc=mydomain,dc=org]. (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [objectClass] (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [uid] (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [userPassword] (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [uidNumber] (Fri Jun 7 15:20:50 2019) [sssd[be[mydomain.org]]] [sdap_get_generic_ext_step] (0x1000): Requesting attrs: [gidNumber]
Authentication via LDAP: where is ldap_search_ext defined?
You're right that defining domains is not well defined. What we plan on doing for (one of) the next version(s) is to make the domains= parameter optional. That way, any defined domain section would automatically be enabled and you could just drop domains and control their order by names of the snippets that include the domains.
Generally, it seems, the idea with conf.d-style directories is to allow a very modular, drop-in method to add features or configurations. With SSSD, specifically, it would seem logical to add further domains to configuration files under /etc/sssd/conf.d/ (RHEL). The domains directive in the [sssd] section of the configuration defines which domains will actually be used. The 'man' pages for SSSD state that conflicting values of a given section/parameter will take the value of the last value based on an alphabetical sorting of the configuration files. Therefore, it isn't really possible to just deploy a new domain configuration without consideration for the existing configuration because, if the new configuration file contained an [sssd]/domains configuration directive containing only the name of the domain in the same file then that may be the only domain that gets configured. It seems most likely that one would still need to modify the [sssd] section of sssd.conf when deploying further configurations to conf.d. This seems like the solution to me but I wanted to query the community to see if there are other, more clever, solutions.
SSSD Domain Configuration Snippets
Figured it out: ldap_user_name
nslcd.conf has "map passwd uid" to map attributes that will be used as the Login username. What is the sssd.conf equivalent of that?
"map passwd uid" equivalent in sssd
I'd say that you shouldn't be adding these SPNs to the host's keytab (computer account) in the first place. Services such as Samba (cifs) or SSH (host) can continue to use it, but everything else (HTTP, imap, etc.) should have their own independent keys in their own keytab files. (Broadly, if the service isn't in AD's default "service aliases" list for 'host', then it shouldn't be sharing the computer account.) The usual way to create additional principals (not associated to the computer account) in Active Directory is to create a user account with a randomized password and assign it the SPNs needed. Active Directory does not use the MIT kadmin protocol; its management is done through LDAP – the only way to create Kerberos principals is the servicePrincipalName LDAP attribute that you've already found. (But don't forget to set msDS-SupportedEncryptionTypes as well!) With the Samba tools, samba-tool spn add and samba-tool domain exportkeytab could be used to achieve this; you could also do it using ktutil to hand-craft a keytab, or even from Windows using RSAT and ktpass.exe. Something like this should work: samba-tool user create HTTP-foo --random-password samba-tool user setexpiry HTTP-foo --noexpiry samba-tool spn add HTTP/foo.example.com HTTP-foo net ads enctypes set HTTP-foo 24 samba-tool domain exportkeytab HTTP.keytab --principal=HTTP/foo.example.com
I'm encountering an issue with the keytab entries that are automatically created when I join a Linux server to an Active Directory domain. First, my process:Install the needed Linux packages yum install realmd pam sssd adcli oddjob oddjob-mkhomedir samba-common-tools krb5-workstation Create Computer object in Active Directory and add the relevant SPN entries (servicePrincipalName) Perform the domain join with realm join -v EXAMPLE.COM -U domainUserDuring the join, the process automatically creates a krb5.keytab file with entries that directly match the Computer object's SPN entries. So if the SPN had an entry of [emailprotected], the join process creates a keytab entry of [emailprotected]. The problem is if the SPN has a capitalized service type included in the name, the keytab generation process doesn't respect the service type case but instead forces the keytab entry to have a lowercase service type. So if the SPN is HTTP/[emailprotected], then the keytab generator forces it to be http/[emailprotected], during the domain join process. In order for the application I'm using to work, these need to match (both be uppercase). With my objective being to have a keytab entry that matches the SPN (uppercase service type), from what I can think of, I have two optionsFix the realm join process to keep the same case for the service type, or Create my own keytab entry into the keytab fileI'm having problems with both options. For the first option, I'm not able to find anything with the join process that can be changed. For the second option, I've found 2 possible applications I could use in order to create my own entry. These applications are kadmin & ktutil. The kadmin gives me an error of "required KADM5 principal missing..." (of which I can't figure out how to fix). And the ktutil option would work, except that it requires the same password be applied to this new keytab entry, that is used by the other keytab entries; however, this password is managed by Active Directory and is not obtainable. Has anyone else run into this before and have a solution on how to keep a keytab entry's service type uppercase? Thanks!
krb5.keytab entries need to have uppercase service type
I was able to finally figure this issue out. There was one main issue:My SSSD config was missing values to define the users shellI was initially alerted to this issue by the following post: Highlight of error in SSH debug Specifically, there was the following line the SSH debug that was indicating the problem client_input_channel_req: channel 0 rtype exit-status reply 0According to this link this shows that a shell cannot be selected for the user. I checked our AD and the attribute for loginShell is populated, but the system doesn't appear to accept this. I added the following lines to my /etc/sssd/sssd.conf file override_shell = /bin/bash shell_fallback = /bin/bashOnce I added these, I was able to successfully login using SSH. I then ran into another problem there the users home directory was not getting created. There is an AD attribute that can control this called unixHomeDirectory. We don't populate this for all users so I added an override for the home directory in the SSSD config as well. override_homedir = /home/%uThe final config for SSSD looks like this: [sssd] domains = example.com config_file_version = 2 services = nss, pam[domain/example.com] ad_domain = example.com krb5_realm = example.com realmd_tags = manages-system joined-with-adcli cache_credentials = True id_provider = ad krb5_store_password_if_offline = True default_shell = /bin/bash override_shell = /bin/bash shell_fallback = /bin/bash ldap_id_mapping = True use_fully_qualified_names = False fallback_homedir = /home/%u override_homedir = /home/%u access_provider = simple simple_allow_users = someuser
I am working on getting SSH to accept AD credentials. Server detailsCentOS 8 Server is successfully joined to the domain Ran realm discover which returned proper information regarding our AD environment realm permit run to permit specific users SSH config file has been slightly modified. It mainly only blocks root logins. SSH to the server using a local user account works. User looking is possible using id someuser. I do not need to append upn suffix (@ad.sample.com).BehaviorWhen signing in via SSH it prompts for user name (provided AD user name), then password (provide AD user password), and after providing the password the SSH session immediately terminates. I can see the request coming in via the /var/log/secure log and I can see that the credentials are being accepted. As soon as it passes authentication though the session is immediately closed. I tested using the wrong credentials for the user and can see this being reported in the secure log as all on the terminal itself. I also tested trying to sign in via the actual server console, it initially appears to let me in, then immediately boots me back to login. Interesting thing from the SSH debug is that the MOTD is visible. When a new user attempts to sign in via SSH their home directory gets created.Part of the output from SSH debug [emailprotected]'s password: debug3: packet_send2: adding 48 (len 72 padlen 8 extra_pad 64) debug2: we sent a password packet, wait for reply debug1: Authentication succeeded (password). Authenticated to x.x.x.x ([x.x.x.x]:xx). debug1: channel 0: new [client-session] debug3: ssh_session2_open: channel_new: 0 debug2: channel 0: send open debug1: Requesting debug1: Entering interactive session. debug1: client_input_global_request: rtype want_reply 0 debug2: callback start debug2: fd 3 setting TCP_NODELAY debug3: packet_set_tos: set IP_TOS 0x10 debug2: client_session2_setup: id 0 debug2: channel 0: request pty-req confirm 1 debug1: Sending environment. debug3: Ignored env XDG_SESSION_ID debug3: Ignored env HOSTNAME debug3: Ignored env TERM debug3: Ignored env SHELL debug3: Ignored env HISTSIZE debug3: Ignored env SSH_CLIENT debug3: Ignored env SSH_TTY debug3: Ignored env USER debug3: Ignored env LS_COLORS debug3: Ignored env MAIL debug3: Ignored env PATH debug3: Ignored env PWD debug1: Sending env LANG = en_US.UTF-8 debug2: channel 0: request env confirm 0 debug3: Ignored env HISTCONTROL debug3: Ignored env SHLVL debug3: Ignored env HOME debug3: Ignored env LOGNAME debug3: Ignored env SSH_CONNECTION debug3: Ignored env LESSOPEN debug3: Ignored env XDG_RUNTIME_DIR debug3: Ignored env _ debug2: channel 0: request shell confirm 1 debug2: callback done debug2: channel 0: open confirm rwindow 0 rmax 32768 debug2: channel_input_status_confirm: type 99 id 0 debug2: PTY allocation request accepted on channel 0 debug2: channel 0: rcvd adjust 2097152 debug2: channel_input_status_confirm: type 99 id 0 debug2: shell request accepted on channel 0 Activate the web console with: systemctl enable --now cockpit.socketLast login: Tue Jun 9 some date from x.x.x.x debug2: channel 0: rcvd eof debug2: channel 0: output open -> drain debug2: channel 0: obuf empty debug2: channel 0: close_write debug2: channel 0: output drain -> closed debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: client_input_channel_req: channel 0 rtype reply 0 debug2: channel 0: rcvd eow debug2: channel 0: close_read debug2: channel 0: input open -> closed debug2: channel 0: rcvd close debug3: channel 0: will not send data after close debug2: channel 0: almost dead debug2: channel 0: gc: notify user debug2: channel 0: gc: user detached debug2: channel 0: send close debug2: channel 0: is dead debug2: channel 0: garbage collecting debug1: channel 0: free: client-session, nchannels 1 debug3: channel 0: status: The following connections are open: #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)Connection to x.x.x.x closed. Transferred: sent 2824, received 2420 bytes, in 0.1 seconds Bytes per second: sent 24722.5, received 21185.7 debug1: Exit status 1Our sssd.conf [sssd] domains = ad.sample.com config_file_version = 2 services = nss, pam[domain/ad.sample.com] ad_domain = ad.sample.com krb5_realm = AD.SAMPLE.COM realmd_tags = manages-system joined-with-adcli cache_credentials = True id_provider = ad krb5_store_password_if_offline = True default_shell = /bin/bash ldap_id_mapping = True #use_fully_qualified_names = True use_fully_qualified_names = False #fallback_homedir = /home/%u@%d fallback_homedir = /home/%u access_provider = simple simple_allow_users = someuserI have checked several posts/blogs about setting this up and I don't think I've missed anything. I should mentioned that I have tried adding SSH to the services section in the sssd.conf file. It didn't make any difference. Does anyone know what else I can check? Or what might be wrong?
SSH disconnecting after successful auth when using AD credentials
use the following configuration item in the sssd.conf to control this: entry_cache_timeout = {time in seconds}e.g. entry_cache_timeout = 30
sssd has the following config to set the interval for the sudo rules refresh: ldap_sudo_full_refresh_intervalWhat is the configuration to set the interval for the netgroup definition retrieval from LDAP?
ldap netgroup refresh interval in SSSD
The easiest method I've found to accomplish this is to SSH to a server which will be picking up the sudo rule and check a user in the group that's being granted this type of access. You can use the sudo commands -l and -U switches:$ man sudo -l, --list If no command is specified, list the allowed (and forbidden) commands for the invoking user (or the user specified by the -U option) on the current host. A longer list format is used if this option is specified multiple times and the security policy supports a ver‐ bose output format.-U user, --other-user=user Used in conjunction with the -l option to list the privileges for user instead of for the invoking user. The security policy may restrict listing other users' privileges. The sudoers policy only allows root or a user with the ALL privilege on the current host to use this option.You can use these together like this: $ sudo -lU <user>Example $ sudo -lU joeuser Matching Defaults entries for joeuser on this host: requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/binUser joeuser may run the following commands on this host: (root) ALL (ALL : ALL) ALLAdditionally you can use multiple -l switches (i.e. -ll) to get a more verbose listing of another user's privileges, for e.g.: $ sudo -llU joeuser Matching Defaults entries for joeuser on this host: !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/binUser joeuser may run the following commands on this host:LDAP Role: lab-data-services-all RunAsUsers: root Commands: ALLLDAP Role: ad-data_services RunAsUsers: root Commands: ALLLDAP Role: ALL RunAsUsers: ALL RunAsGroups: ALL Commands: ALLsudo version $ sudo -V Sudo version 1.8.6p3 Sudoers policy plugin version 1.8.6p3 Sudoers file grammar version 42 Sudoers I/O plugin version 1.8.6p3
I currently manage an IDM (FreeIPA) cluster and have full sudo rights, i.e. I can become root via sudo -Es. I'd like to verify a sudo rule that I've added to FreeIPA on a specific server to confirm that the rule is being picked up properly by the host via SSSD. How can I do this? NOTE: the sudo rule is as follows: $ ipa sudorule-show prod-abc-dashboard-dba Rule name: prod-abc-dashboard-dba Enabled: TRUE Command category: all User Groups: eng-data-svc
How can I confirm another user's sudo permissions using my sudo permissions?
The configuration file /etc/sssd/sssd.conf needs the following entry. [domain/your.domain] ad_gpo_access_control = permissiveI found the solution at the Ubuntu sssd bug page
After migration form debian jessie to stretch - login over ssh fails for Ad users, also su to AD user (sssd env) fails. Any hints? Log lines: Jun 20 12:48:57 myhost sshd[1736]: pam_sss(sshd:account): Access denied for user testuser: 4 (System error) Jun 20 12:48:57 myhost sshd[1736]: fatal: Access denied for user testuser by PAM account configuration [preauth] Jun 20 12:49:09 myhost su[1776]: pam_unix(su:auth): authentication failure; logname=service uid=1000 euid=0 tty=/dev/pts/1 ruser=service rhost= user=testuser Jun 20 12:49:10 myhost su[1776]: pam_sss(su:auth): authentication success; logname=service uid=1000 euid=0 tty=/dev/pts/1 ruser=service rhost= user=testuser Jun 20 12:49:10 myhost su[1776]: pam_sss(su:account): Access denied for user testuser: 4 (Systemfehler) Jun 20 12:49:10 myhost su[1776]: pam_acct_mgmt: System error Jun 20 12:49:10 myhost su[1776]: FAILED su for testuser by service Jun 20 12:49:10 myhost su[1776]: - /dev/pts/1 service:testuser
sssd / ad no ssh login after migration debian 8 => 9: Access denied for user xxx: 4 (System error)
The SSSD docs cover this in some detail. Essentially, by default when SSSD is used to join a new domain, it assigns a block of UID's designed to be unique to that domain, that override any that AD might have assigned. This allows multiple domains to be used, and ensure that users from all domains get unique UID's. This portion of the docs, I think gives you the info you need. (Basically, set ldap_id_mapping = False, restart SSSD and clear caches)
I use an Active Directory server for authentication,Solaris works fine following this Howto. All works,and my user "user1" get the right UID assigned on Windows AD,which is 10000. On linux I follow this howto and I can join the AD..user works but..id is totally different,not 10000 but "uid=744201108",how to get the correct uid on linux? This is my sssd [sssd] domains = server.example config_file_version = 2 services = nss, pam[domain/server.example] ad_domain = server.example krb5_realm = SERVER.EXAMPLE realmd_tags = manages-system joined-with-adcli cache_credentials = True id_provider = ad krb5_store_password_if_offline = True default_shell = /bin/bash ldap_id_mapping = True use_fully_qualified_names = false fallback_homedir = /home/%u@%d access_provider = ad# needed to use correct active directory properties (Windows Server 2003) ldap_schema = ad ldap_user_object_class = person ldap_user_name = msSFU30Name ldap_user_uid_number = msSFU30UidNumber ldap_user_gid_number = msSFU30GidNumber ldap_user_home_directory = msSFU30HomeDirectory ldap_user_shell = msSFU30LoginShell ldap_user_gecos = displayName ldap_group_object_class = group ldap_group_name = msSFU30Name ldap_group_gid_number = msSFU30GidNumber# id ldap_idmap_autorid_compat = true
On Solaris I get good id mapping..on linux not,why?
Version 1.11.7-2 from testing works for me in a production environment. You don't need to upgrade your entire system from stable, just add a testing repository: deb http://ftp.uk.debian.org/debian/ testing main contrib non-free deb http://ftp.uk.debian.org/debian/ testing-updates main contrib non-freeYou may need to tell apt that you prefer the Stable release. You do this by adding this section to a file such as /etc/apt/apt.conf.d/00local APT { Default-Release "stable"; // Cache-Limit "50000000"; // only if needed };Then run aptitude update and you should find that aptitude install -t testing sssd-ad offers to install that and upgrade sssd, etc. Just for completeness here is my (redacted) sssd.conf [sssd] config_file_version = 2 reconnection_retries = 3 sbus_timeout = 30 services = nss, pam domains = example.org[nss] filter_groups = root filter_users = root reconnection_retries = 3[pam] reconnection_retries = 3 offline_credentials_expiration = 7 offline_failed_login_delay = 1[domain/example.org] enumerate = false ldap_group_nesting_level = 5 ldap_use_tokengroups = false cache_credentials = true account_cache_expiration = 10 entry_cache_timeout = 14400 lookup_family_order = ipv4_only dns_resolver_timeout = 3 dns_discovery_domain = example.org fallback_homedir = /home/%d/%u default_shell = /bin/bash id_provider = ad
I have a similar question running on serverfault, but i have a followup question that is more suited here, in my humble(likely uninformed) opinion. I have been trying to validate users in my Debian Wheezy server against the company AD(windows 2008 server). The main challenge is that this AD does not supply any Unix attributes (uid, gid, homedir, shell). I have gotten around homedir and shell by using sssd and its fallback mechanisms. However, i am currently stuck on the uid, gid. When i attempt to sync using the configuration (i cut it down to the relevant parts) id_provider = ad access_provider = ad auth_provider = krb5 chpass_provider = krb5 ldap_schema = ad ldap_id_mapping = true debug_level = 7I get the following error: (Tue Jan 27 10:39:05 2015) [sssd[be[thecompany.dk]]] [sbus_dispatch] (0x0080): Connection is not open for dispatching. (Tue Jan 27 10:39:05 2015) [sssd[be[thecompany.dk]]] [be_client_destructor] (0x0400): Removed PAM client (Tue Jan 27 10:39:05 2015) [sssd[be[thecompany.dk]]] [sbus_dispatch] (0x0080): Connection is not open for dispatching. (Tue Jan 27 10:39:05 2015) [sssd[be[thecompany.dk]]] [be_client_destructor] (0x0400): Removed NSS client (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [server_setup] (0x0080): CONFDB: /var/lib/sss/db/config.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [recreate_ares_channel] (0x0100): Initializing new c-ares channel (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [resolv_get_family_order] (0x1000): Lookup order: ipv4_first (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [fo_context_init] (0x0080): Created new fail over context, retry timeout is 30 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [confdb_get_domain_internal] (0x0020): No enumeration for [thecompany.dk]! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sysdb_domain_init_internal] (0x0200): DB File for thecompany.dk: /var/lib/sss/db/cache_thecompany.dk.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [ldb] (0x0400): asq: Unable to register control with rootdse! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_init_connection] (0x0200): Adding connection FB1630 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [monitor_common_send_id] (0x0100): Sending ID: (%BE_thecompany.dk,1) (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [create_socket_symlink] (0x1000): Symlinking the dbus path /var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4798 to a link /var/lib/sss/pipes/private/sbus-dp_thecompany.dk (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_new_server] (0x0080): D-BUS Server listening on unix:path=/var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4798,guid=84361ff4e288ffa9288b858f54c75cba (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x1000): Loading backend [ad] with path [/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so]. (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x0010): Unable to load ad module with path (/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so), error: /usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so: cannot open shared object file: No such file or directory (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [be_process_init] (0x0010): fatal error initializing data providers (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [main] (0x0010): Could not initialize backend [79] (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [server_setup] (0x0080): CONFDB: /var/lib/sss/db/config.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [recreate_ares_channel] (0x0100): Initializing new c-ares channel (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [resolv_get_family_order] (0x1000): Lookup order: ipv4_first (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [fo_context_init] (0x0080): Created new fail over context, retry timeout is 30 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [confdb_get_domain_internal] (0x0020): No enumeration for [thecompany.dk]! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sysdb_domain_init_internal] (0x0200): DB File for thecompany.dk: /var/lib/sss/db/cache_thecompany.dk.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [ldb] (0x0400): asq: Unable to register control with rootdse! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_init_connection] (0x0200): Adding connection 1A3D630 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [monitor_common_send_id] (0x0100): Sending ID: (%BE_thecompany.dk,1) (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [create_socket_symlink] (0x1000): Symlinking the dbus path /var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4799 to a link /var/lib/sss/pipes/private/sbus-dp_thecompany.dk (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_new_server] (0x0080): D-BUS Server listening on unix:path=/var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4799,guid=f69da63ecb7352f94fee01df54c75cba (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x1000): Loading backend [ad] with path [/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so]. (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x0010): Unable to load ad module with path (/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so), error: /usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so: cannot open shared object file: No such file or directory (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [be_process_init] (0x0010): fatal error initializing data providers (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [main] (0x0010): Could not initialize backend [79] (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [server_setup] (0x0080): CONFDB: /var/lib/sss/db/config.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [recreate_ares_channel] (0x0100): Initializing new c-ares channel (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [resolv_get_family_order] (0x1000): Lookup order: ipv4_first (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [fo_context_init] (0x0080): Created new fail over context, retry timeout is 30 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [confdb_get_domain_internal] (0x0020): No enumeration for [thecompany.dk]! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sysdb_domain_init_internal] (0x0200): DB File for thecompany.dk: /var/lib/sss/db/cache_thecompany.dk.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [ldb] (0x0400): asq: Unable to register control with rootdse! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_init_connection] (0x0200): Adding connection 210B630 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [monitor_common_send_id] (0x0100): Sending ID: (%BE_thecompany.dk,1) (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [create_socket_symlink] (0x1000): Symlinking the dbus path /var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4800 to a link /var/lib/sss/pipes/private/sbus-dp_thecompany.dk (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_new_server] (0x0080): D-BUS Server listening on unix:path=/var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4800,guid=466e1c905c470ad8c00455f754c75cba (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x1000): Loading backend [ad] with path [/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so]. (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x0010): Unable to load ad module with path (/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so), error: /usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so: cannot open shared object file: No such file or directory (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [be_process_init] (0x0010): fatal error initializing data providers (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [main] (0x0010): Could not initialize backend [79] (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [server_setup] (0x0080): CONFDB: /var/lib/sss/db/config.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [recreate_ares_channel] (0x0100): Initializing new c-ares channel (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [resolv_get_family_order] (0x1000): Lookup order: ipv4_first (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [fo_context_init] (0x0080): Created new fail over context, retry timeout is 30 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [confdb_get_domain_internal] (0x0020): No enumeration for [thecompany.dk]! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sysdb_domain_init_internal] (0x0200): DB File for thecompany.dk: /var/lib/sss/db/cache_thecompany.dk.ldb (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [ldb] (0x0400): asq: Unable to register control with rootdse! (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_init_connection] (0x0200): Adding connection 1811630 (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [monitor_common_send_id] (0x0100): Sending ID: (%BE_thecompany.dk,1) (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [create_socket_symlink] (0x1000): Symlinking the dbus path /var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4801 to a link /var/lib/sss/pipes/private/sbus-dp_thecompany.dk (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [sbus_new_server] (0x0080): D-BUS Server listening on unix:path=/var/lib/sss/pipes/private/sbus-dp_thecompany.dk.4801,guid=7410c96282fd44c81ae85d5454c75cba (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x1000): Loading backend [ad] with path [/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so]. (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [load_backend_module] (0x0010): Unable to load ad module with path (/usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so), error: /usr/lib/x86_64-linux-gnu/sssd/libsss_ad.so: cannot open shared object file: No such file or directory (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [be_process_init] (0x0010): fatal error initializing data providers (Tue Jan 27 10:39:06 2015) [sssd[be[thecompany.dk]]] [main] (0x0010): Could not initialize backend [79]The files are actually missing: /usr/lib/x86_64-linux-gnu/sssd$ ls -la total 3884 drwxr-xr-x 3 root root 4096 Jan 26 15:05 . drwxr-xr-x 11 root root 12288 Jan 26 15:05 .. -rw-r--r-- 1 root root 1405048 Mar 4 2013 libsss_ipa.so -rw-r--r-- 1 root root 585784 Mar 4 2013 libsss_krb5.so -rw-r--r-- 1 root root 1081880 Mar 4 2013 libsss_ldap.so -rw-r--r-- 1 root root 479160 Mar 4 2013 libsss_proxy.so -rw-r--r-- 1 root root 389400 Mar 4 2013 libsss_simple.so drwxr-xr-x 2 root root 4096 Jan 26 15:05 modulesHow do i get hold of the sssd ad provider for sssd on Debian Wheezy? I have seen numerous examples of it in use. Is it really not included in the wheezy distribution? Can i get around it by using the ldap provider somehow? Or do i have to smuss up my server and add the unstable repository to my sources?
sssd-ad in wheezy
If I understood correctly, nscd caches password for 10 min for each login.No, it only caches the user information that would be found in /etc/passwd, which is generally everything except the password. That would be the shadow map – but most LDAP configurations do not use shadow; they don't reveal the password hash to nsswitch at all.does this give me the ability to login, within 24 hrs, when ldap server is down?Most likely not. In nearly all setups, login through LDAP is not done through nsswitch (i.e. not by retrieving the password hash for local verification); it's done by PAM actively contacting the LDAP server and having it verify the password. The only way to cache that is via PAM. If your pam_ldap module doesn't have caching built-in, the pam_ccache module can be inserted above it to provide something similar. Alternatively, if you are really looking for redundancy, then set up a second LDAP server. Use OpenLDAP's "Syncrepl" to have it automatically replicate data (optionally even in both directions). (It's pretty odd that your LDAP server is more susceptible to power outages than the rest of your network, but if e.g. there are multiple circuits, then place the 2nd server on the circuit that has fewer outages...)
as I mentioned in another thread, I have an LDAP system supporting two dozen Linux servers. When LDAP server is down for various reasons (firewall rule changes, power outage etc), my rest of the systems became hanged. I am hoping to build some redundancy, and stumbled upon articles on using nscd or sssd for caching logins locally. all my servers have nscd installed, with the following settings enable-cache passwd yes positive-time-to-live passwd 600these are default settings. If I understood correctly, nscd caches password for 10 min for each login. to handle unexpected ldap server downtime, I am wondering if I can increase the positive-time-to-live to a larger number, say a full day (86400 s). does this give me the ability to login, within 24 hrs, when ldap server is down? is there any risk doing this? I saw in various threads that sssd serves similar purposes, although I tried it, and it broke my PAM settings and make all login "permission denied". without being able to figure out why, I decided to remove sssd for now (), and focus on using nscd instead. all my servers run ubuntu on various LTS versions
Understanding risks of setting nscd positive-time-to-live to a longer duration
In this case the problem actually resided in the vendor application doing the authentication that did not trigger the PAM modules for the session, a modification on this vendor application's configuration allowed the authentication process to invoke the PAM session configuration we have set for creating the home directory.
I have a vendor application installed in an Ubuntu Jammy server that relies on SSSD v2.6.3 configured for LDAP integration for the authentication and creation of the home directory of the user in the server. In the sssd.conf configuration it is present: [sssd] config_file_version=2 reconnection_retries=3 services=nss,pam domains=mydomain.com[nss] ...[pam] ...[domain/mydomain.com] ... ldap configuration ... override_homedir=/sfs/home/%uWhen user is authenticated the home directory created has the following set of permissions: $ ls -lhtar /sfs/home drwxr-xr-x 3 myuser mygroup 4.0K Jan 3 19:23 myuserUnfortunately the permissions drwxr-xr-x give also access to others to navigate in their home directory. At the beginning I thought this was controlled by the PAM modules, in particular, the common-session executing the pam_mkhomedir.so module, however this is not the case!!!, since commenting this module does not have any effect, and also the home directory is always completely empty, not following the home "skeleton" usually provided in the mkhomedir e.g. session required pam_mkhomedir.so skel=/etc/skel/. I also noticed that the permissions drwxr-xr-x correspond to a umask 022 which is usually the default in the linux distributions, so I have modify to a 006 in /etc/login.defs and also add the umask 006 in /etc/profile to avoid the use of the 022 umask, however this attempt has been also in vain. is there anyone out there that has had this issue? How can you force the right umask when home directory creation is being triggered by the SSSD service? Thank you so much in advance!
Why SSSD Service override_homedir triggers creation of home directory with wrong permissions?
Is there a way to keep the ticket service forwarded to openssh inside a credential cache? It would help me to authenticate sudo afterward.No, there's no option to do that. (It would be possible in theory, but it's not an implemented function.) However, it might be possible to use PAM to acquire a "S4U2self" ticket, where the service uses its own keytab to get a ticket to itself "on behalf of" the user. (See e.g. kvno -I.) (Also it's called a service ticket, not ticket service.)If 1 is not possible (and i guess it is indeed not), are there any security concerns about forwarding TGT on all of our servers? (TGT lifetime is 4 hours).There are, very similar to SSH agent forwarding. Even though the long-term credentials cannot be stolen, the 4-hour TGT in theory could be stolen (and extended all the way up to their renewable lifetime – not just up to their normal lifetime). It's up to you to decide whether that's a significant concern in your case, i.e. how hardened the servers are against someone getting root access and reading other users' tickets.I would have to open a flow between servers and KDC port 88 on our firewall.That shouldn't be an issue. (In fact, I don't understand why that isn't already open.)I'd rather avoid NOPASSWD inside sudoers, but if members of group sudo authenticate via kerberos, are there any security concerns about putting NOPASSWD inside sudoers for that group?What you're planning already functions like NOPASSWD – the idea is that if pam_sss_gssapi succeeds, it will immediately return out of PAM without reaching the "ask for password" pam_unix module at all. However, if you enabled NOPASSWD, it would bypass the Kerberos authentication as well. The reason is that Sudo doesn't prompt for password explicitly – it only calls PAM to authenticate the user, and the NOPASSWD flag actually means "no PAM authentication". (It does not mean "no password" as such; it just happens that the standard PAM module (pam_unix) asks for a password.) But if you enable NOPASSWD, then sudo will never call PAM for auth, therefore skipping both pam_unix and pam_sss_gss.Windows Kerberos uses PAC to forward groups membership. Do you have any idea why is that feature not implemented in MIT Kerberos?MIT Kerberos, being the "original" Kerberos distribution, continues to follow its original design where authorization (access control) is explicitly not part of Kerberos functionality – it is purely an authentication system.I mean NSS from Linux has to poll the LDAP frequently to feed its databases about the users and groups.It doesn't poll LDAP at any frequency; it queries LDAP only when a user is "logged in" – not significantly different from Windows.
By now, we are using OpenSSH GSSAPI authentication on all of our servers (Debian from 10 to 12). Then we sudo -i, using ldap authentication (through sssd-ldap). I would like to get rid of the ldap authentication and rely on GSSAPI only, both for OpenSSH and Sudo. The idea is to to forward Ticket service to Openssh (host/fqdn), keep it in the credentials cache (typically /tmp/krb5...) and keep that TGS to also authenticate sudo (I found that pam_sss_gss.so could authenticate sudo with GSSAPI). The problem is...OpenSSH destroys the Ticket service once it's validated. Here are my questions:Is there a way to keep the ticket service forwarded to openssh inside a credential cache? It would help me to authenticate sudo afterward. If 1 is not possible (and i guess it is indeed not), are there any security concerns about forwarding TGT on all of our servers? (TGT lifetime is 4 hours). I would have to open a flow between servers and KDC port 88 on our firewall. I'd rather avoid NOPASSWD inside sudoers, but if members of group sudo authenticate via kerberos, are there any security concerns about putting NOPASSWD inside sudoers for that group? Let me know whether you have other ideas, i would really appreciate it.Thank you.
How to authenticate through OpenSSH then sudo with only one Ticket Service (Kerberos TGS host/fqdn)
Stop using sssd. From Samba >= 4.8.0, Shares and sssd are incompatible. If you want shares, then you must use winbind.
I have a RHEL 7.6 server joined to AD using sssd and realm. I am able to SSH into the Linux servers as AD users, but the same users are unable to access the Samba share configured in the server. When I try to access the share from Windows Server 2012 R2 Standard, it keeps prompting me for the password. This is how I configured smb.conf: client signing =yes client use spnego =yes kerberos method = secrets and keytab log file = /var/log/samba/%m.log ###ntlm auth =yes ### template homedir = /home/%U idmap config * : backend = tdb idmap config * : range = 10000-199999 idmap config DOMAIN: backend = sss idmap config DOMAIN : range = 200000-2147483647Please check and let me know how I can let AD users to access the shared directories.
AD users unable to access Samba Share
The PAM modules involved in vsFTPd authentication are defined in /etc/pam.d/vsftpd. By default, it has a line: auth include password-authwhich uses the system-wide default PAM configuration for password-based authentication that is specified in /etc/pam.d/password-auth. When AD authentication is configured, the relevant PAM modules are typically added to /etc/pam.d/password-auth. If you don't want AD authentication to work at all with vsFTPd, edit /etc/pam.d/vsftpd file. Comment out the line auth include password-authand after the commented-out line, write in the relevant lines from the password-auth file as it exists in a system with no AD authentication configured: auth required pam_env.so auth required pam_faildelay.so delay=2000000 auth sufficient pam_unix.so nullok try_first_pass auth requisite pam_succeed_if.so uid >= 1000 quiet_success auth required pam_deny.soIn this way, the AD authentication provider module will be completely prevented from participating in the vsFTPd authentication, so for vsFTPd the authentication process happens just as if the system did not have any AD integration at all.
I have a very small vm installed, for testing purposes, running CentOS 1708, with vsftp configured. i used https://www.rootusers.com/how-to-join-centos-linux-to-an-active-directory-domain/ to setup ad authentication for the OS part, but did not want ad users to be able to login via FTP client. Primarily i need the ad authentication for administration purposes via ssh internally, not over the internet, and FTP logins purely via local users. i noticed that if a user has not logged in on this vm via ssh, he/she cannot login via ftp port 21 using ad credentials, as it fails to create home directory. which is fine i guess, but i am looking for a way to prevent ad auth via AD completely, only allowed via ssh or terminal I do not want ad authentication via ftp as that then puts my ad users on the internet at risk of being "hacked" or locked out any suggestions on how i can accomplish this?
Prevent vsFTP auth via AD
The following seem to describe configured automount maps in a way that alleviates the need to learn ldap. You might need to be root for it to work. automount --dumpmaps
I just got a user account on a server with its nsswitch pointing at ldap. Something is wrong with my home folder (I don't have one). Generally the home folders are mounted by automount/autofs and the automount maps are in ldap. In the bad old days of NIS it would have been as easy as ypcat auto.home | grep myusername to verify if the automount map had sane data. In Solaris they seem to have similar features built into getent. How can I query the automount maps in CentOS 6 type Linux? I do not have ldapsearch available, nor do I know what ldap server I'm using or how the catalog is structured. So I don't think manual ldap queries is much of an option.
Linux getent automount?
I figured out the issue, SSH Sessions Credentials were being cached in my terminal. MobaX freeware was being used with "save password" defaults to yes. Cleared the password vault. ¯\_(ツ)_/¯ ¯\_(ツ)_/¯
I have setup Redhat host to authenticate AD users for ssh sessions. Everything is working as expected, however, single concern, user credentials are being cached somewhere. Upon first time login using ssh, user is asked to enter the password however, later on (second third attempts etc), whenever user initiates the ssh connection, ssh connection is established without even prompting to enter the password. This could be a security risk. How can I prevent caching the credentials and have the user enter password each time when they want to connect to the RHEL server./etc/sssd/sssd.conf[nss] filter_groups = root filter_users = root reconnection_retries = 3[pam] reconnection_retries = 3[domain/example.com] ad_domain = example.com krb5_realm = EXAMPLE.COM realmd_tags = manages-system joined-with-samba cache_credentials = false id_provider = ad krb5_store_password_if_offline = True default_shell = /bin/bash ldap_id_mapping = True use_fully_qualified_names = True fallback_homedir = /home/%u@%d access_provider = simple simple_allow_groups = Domain Admins
sssd caching user credentials even the cache_credentials is set to false
Using different keytabs for each machine allows you to selectively remove systems from your domain. If a single one of your systems was compromised, and you used the same keytab for all of your systems, and you want to boot the rogue system from your domain, you'll be forced to revoke the keytab from the AD server for all of your systems, not just the rogue system's keytab.
Today I use the same keytab for all Linux servers (hundreds). I'm considering using a different keytab for each machine because I suppose that if I use the same keytab the Active Directory thinks I have only one machine but apart from this I don't see many benefits of using different keytabs. Why should I use a different keytab for each Linux server that authenticates against Active Directory?
What problems could I have if I use the same keytab for all Linux servers authenticating against Active Directory?
Looking at the log files with debug_level = 6 enabled, it's evident that the LDAP query is being performed but no results are returned:[RID#6] Searching for users with base [dc=my,dc=domain,dc=com] [RID#6] calling ldap_search_ext with [(&(sAMAccountName=John)(objectclass=user)(sAMAccountName=*)(&(uidNumber=*)(!(uidNumber=0))))][dc=my,dc=domain,dc=com]. [RID#6] Search result: Success(0), no errmsg set [RID#6] Search for users, returned 0 results.The issue here turns out to be that the uidNumber value is not populated in the Active Directory (AD/LDAP) source. The correct solution here is to ensure that the UID and GID are derived from the AD SID value: ldap_id_mapping = true
I am struggling with making sssd use LDAP users to login on my Linux-Server (Oracle Linux 8.9, basically identical to RHEL, but free). Goal Using the users (e.g. "John") existing on the LDAP-Server (Microsoft AD DC) to log in on my Linux-Server Current Errors Whenever I enter the command "id John" or "su - John" I receive the error "no such user". Strangely, all my sssd logs are not showing anything. The logs itself are working, because I had other issues before (e.g. "Port working, but In order to perform this operation a successful bind must be completed on the connection"), but I managed to solve all this problems using the logs. But currently, nothing new gets printed to the logs, no matter if I use "id" or "su" What is working "ldapsearch" is working perfectly fine and prints out my LDAP-Tree - including "John" ldapsearch -D "CN=mybind,OU=myunit,DC=my,DC=domain,DC=com" -WRight now I really do not have any idea anymore why it is not working. I double and triple checked all IPs etc. In my opinion it should work, or at least give me usable logs. Any help is appreciated. /etc/openldap/ldap.conf # See ldap.conf(5) for details # This file should be world readable but not world writable.BASE DC=my,DC=domain,DC=com URI ldaps://dc.my.domain.com:636 TLS_CACERT /etc/openldap/cacerts/ca.cert.pem TLS_CACERTDIR /etc/openldap/cacerts#SIZELIMIT 12 #TIMELIMIT 15 #DEREF never# When no CA certificates are specified the Shared System Certificates # are in use. In order to have these available along with the ones specified # by TLS_CACERTDIR one has to include them explicitly: #TLS_CACERT /etc/pki/tls/cert.pem# System-wide Crypto Policies provide up to date cipher suite which should # be used unless one needs a finer grinded selection of ciphers. Hence, the # PROFILE=SYSTEM value represents the default behavior which is in place # when no explicit setting is used. (see openssl-ciphers(1) for more info) #TLS_CIPHER_SUITE PROFILE=SYSTEM# Turning this off breaks GSSAPI used with krb5 when rdns = false #SASL_NOCANON on/etc/sssd/sssd.conf [sssd] config_file_version = 2 services = nss, pam, autofs domains = default [nss] homedir_substring = /export/home [pam] [domain/default] id_provider = ldap autofs_provider = ldap auth_provider = ldap chpass_provider = ldap ldap_schema = AD ldap_uri = ldaps://dc.my.domain.com:636 ldap_chpass_uri = ldaps://dc.my.domain.com:636 ldap_search_base = DC=my,DC=domain,DC=com ldap_id_use_start_tls = False ldap_tls_cacertdir = /etc/openldap/cacerts ldap_tls_reqcert = demand cache_credentials = False entry_cache_timeout = 600 ldap_network_timeout = 3 ldap_connection_expire_timeout = 60 ldap_default_bind_dn = CN=mybind,OU=myunit,DC=my,DC=domain,DC=com ldap_default_authtok = mypassword/etc/nsswitch.conf # Generated by authselect on Tue May 7 10:30:31 2024 # Do not modify this file manually.# If you want to make changes to nsswitch.conf please modify # /etc/authselect/user-nsswitch.conf and run 'authselect apply-changes'. # # Note that your changes may not be applied as they may be # overwritten by selected profile. Maps set in the authselect # profile takes always precedence and overwrites the same maps # set in the user file. Only maps that are not set by the profile # are applied from the user file. # # For example, if the profile sets: # passwd: sss files # and /etc/authselect/user-nsswitch.conf contains: # passwd: files # hosts: files dns # the resulting generated nsswitch.conf will be: # passwd: sss files # from profile # hosts: files dns # from user filepasswd: files sss systemd group: files sss systemd netgroup: sss files automount: sss files services: sss files# Included from /etc/authselect/user-nsswitch.conf# # /etc/nsswitch.conf # # Name Service Switch config file. This file should be # sorted with the most-used services at the beginning. # # Valid databases are: aliases, ethers, group, gshadow, hosts, # initgroups, netgroup, networks, passwd, protocols, publickey, # rpc, services, and shadow. # # Valid service provider entries include (in alphabetical order): # # compat Use /etc files plus *_compat pseudo-db # db Use the pre-processed /var/db files # dns Use DNS (Domain Name Service) # files Use the local files in /etc # hesiod Use Hesiod (DNS) for user lookups # nis Use NIS (NIS version 2), also called YP # nisplus Use NIS+ (NIS version 3) # # See `info libc 'NSS Basics'` for more information. # # Commonly used alternative service providers (may need installation): # # ldap Use LDAP directory server # myhostname Use systemd host names # mymachines Use systemd machine names # mdns*, mdns*_minimal Use Avahi mDNS/DNS-SD # resolve Use systemd resolved resolver # sss Use System Security Services Daemon (sssd) # systemd Use systemd for dynamic user option # winbind Use Samba winbind support # wins Use Samba wins support # wrapper Use wrapper module for testing # # Notes: # # # WARNING: Running nscd with a secondary caching service like sssd may # lead to unexpected behaviour, especially with how long # entries are cached. # # Installation instructions: # # To use 'db', install the appropriate package(s) (provide 'makedb' and # libnss_db.so.*), and place the 'db' in front of 'files' for entries # you want to be looked up first in the databases, like this: # # passwd: db files # shadow: db files # group: db files# In order of likelihood of use to accelerate lookup. shadow: files sss hosts: files dns myhostnamealiases: files ethers: files gshadow: files # Allow initgroups to default to the setting for group. # initgroups: files networks: files dns protocols: files publickey: files rpc: filesUpdate ssd_default.log with debug_level 6 (2024-05-08 7:59:45): [be[default]] [dp_get_account_info_send] (0x0200): Got request for [0x1][BE_REQ_USER][name=John@default] (2024-05-08 7:59:45): [be[default]] [dp_attach_req] (0x0400): [RID#6] DP Request [Account #6]: REQ_TRACE: New request. [sssd.nss CID #2] Flags [0x0001]. (2024-05-08 7:59:45): [be[default]] [dp_attach_req] (0x0400): [RID#6] Number of active DP request: 1 (2024-05-08 7:59:45): [be[default]] [sdap_search_user_next_base] (0x0400): [RID#6] Searching for users with base [dc=my,dc=domain,dc=com] (2024-05-08 7:59:45): [be[default]] [sdap_get_generic_ext_step] (0x0400): [RID#6] calling ldap_search_ext with [(&(sAMAccountName=John)(objectclass=user)(sAMAccountName=*)(&(uidNumber=*)(!(uidNumber=0))))][dc=my,dc=domain,dc=com]. (2024-05-08 7:59:45): [be[default]] [sdap_get_generic_op_finished] (0x0400): [RID#6] Search result: Success(0), no errmsg set (2024-05-08 7:59:45): [be[default]] [sdap_search_user_process] (0x0400): [RID#6] Search for users, returned 0 results. (2024-05-08 7:59:45): [be[default]] [sysdb_search_by_name] (0x0400): [RID#6] No such entry (2024-05-08 7:59:45): [be[default]] [sysdb_delete_user] (0x0400): [RID#6] Error: 2 (No such file or directory) (2024-05-08 7:59:45): [be[default]] [dp_req_done] (0x0400): [RID#6] DP Request [Account #6]: Request handler finished [0]: Success (2024-05-08 7:59:45): [be[default]] [_dp_req_recv] (0x0400): [RID#6] DP Request [Account #6]: Receiving request data. (2024-05-08 7:59:45): [be[default]] [dp_req_destructor] (0x0400): [RID#6] DP Request [Account #6]: Request removed. (2024-05-08 7:59:45): [be[default]] [dp_req_destructor] (0x0400): [RID#6] Number of active DP request: 0 (2024-05-08 7:59:45): [be[default]] [sbus_issue_request_done] (0x0400): sssd.dataprovider.getAccountInfo: Success (2024-05-08 7:59:45): [be[default]] [dp_get_account_info_send] (0x0200): Got request for [0x1][BE_REQ_USER][idnumber=John] (2024-05-08 7:59:45): [be[default]] [dp_attach_req] (0x0400): [RID#7] DP Request [Account #7]: REQ_TRACE: New request. [sssd.nss CID #2] Flags [0x0001]. (2024-05-08 7:59:45): [be[default]] [dp_attach_req] (0x0400): [RID#7] Number of active DP request: 1 (2024-05-08 7:59:45): [be[default]] [sdap_search_user_next_base] (0x0400): [RID#7] Searching for users with base [dc=my,dc=domain,dc=com] (2024-05-08 7:59:45): [be[default]] [sdap_get_generic_ext_step] (0x0400): [RID#7] calling ldap_search_ext with [(&(uidNumber=John)(objectclass=user)(sAMAccountName=*)(&(uidNumber=*)(!(uidNumber=0))))][dc=my,dc=domain,dc=com]. (2024-05-08 7:59:45): [be[default]] [sdap_get_generic_op_finished] (0x0400): [RID#7] Search result: Success(0), no errmsg set (2024-05-08 7:59:45): [be[default]] [sdap_search_user_process] (0x0400): [RID#7] Search for users, returned 0 results. (2024-05-08 7:59:45): [be[default]] [sysdb_search_user_by_uid] (0x0400): [RID#7] No such entry (2024-05-08 7:59:45): [be[default]] [sysdb_delete_user] (0x0400): [RID#7] Error: 2 (No such file or directory) (2024-05-08 7:59:45): [be[default]] [dp_req_done] (0x0400): [RID#7] DP Request [Account #7]: Request handler finished [0]: Success (2024-05-08 7:59:45): [be[default]] [_dp_req_recv] (0x0400): [RID#7] DP Request [Account #7]: Receiving request data. (2024-05-08 7:59:45): [be[default]] [dp_req_destructor] (0x0400): [RID#7] DP Request [Account #7]: Request removed. (2024-05-08 7:59:45): [be[default]] [dp_req_destructor] (0x0400): [RID#7] Number of active DP request: 0 (2024-05-08 7:59:45): [be[default]] [sbus_issue_request_done] (0x0400): sssd.dataprovider.getAccountInfo: Success
"no such user" - LDAP authentication with sssd
Maybe, I found the solution. I'm using SSS which is using OpenLDAP not LDAP. So, is it possible to switch "sss" parameter before "files" in order to run sssd on the right way. .... passwd: sss files shadow: sss files group: sss files ....
I've got a CentOS7 server joined to a Windows Active Directory Server. I'm trying to connect to CentOS using my Active Directory credentials but it seems that it checks the local account as first step and LDAP as second. That's because I'm receiving a message that order me to change the local account password. Is there a way to change the authentication order in order to check LDAP as first step and local account as second? This is my nsswitch.conf .... passwd: ldap files sss shadow: ldap files sss group: ldap files sss ....
Change authentication order GNU/Linux
I needed to point /usr/lib/libwbclient.so.* libraries to /usr/lib/sssd/modules/libwbclient.so.*. I sent a bug report for Gentoo to properly handle it.
I have configured the users through SSSD native AD support. However when I try to access the share it's mapped as "Unix User\username@domain" instead of "domain\username". My sssd: [sssd] config_file_version = 2 domains = domain.com services = nss, pam[nss][pam][domain/domain.com] cache_credentials = true id_provider = ad auth_provider = ad access_provider = simple default_shell = /bin/zsh fallback_homedir = /home/%d/%u simple_allow_users = [emailprotected] use_fully_qualified_names = true ldap_id_mapping = true ldap_schema = ad ldap_idmap_range_min = 100000 ldap_idmap_range_max = 2000100000 ldap_idmap_range_size = 200000000 ldap_idmap_default_domain = DOMAIN.COM ignore_group_members = trueMy krb: [libdefaults] default_realm = DOMAIN.COM clockskew = 300 ticket_lifetime = 1d forwardable = true proxiable = true dns_lookup_realm = true dns_lookup_kdc = true allow_weak_crypto = true[realms] DOMAIN.COM = { default_domain = DOMAIN.COM auth_to_local = RULE:[1:$1@$0](^.*@DOMAIN.COM$)s/@DOMAIN.COM/@domain.com/ }[domain_realm] .kerberos.server = DOMAIN.COM .domain.com = DOMAIN.COM domain.com = DOMAIN.COM domain = DOMAIN.COM[appdefaults] pam = { ticket_lifetime = 1d renew_lifetime = 1d forwardable = true proxiable = false retain_after_close = false minimum_uid = 0 debug = false }[logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/kdc.log admin_server = FILE:/var/log/kadmind.logMy samba: [Global] netbios name = HOSTNAME workgroup = DOMAIN.COM realm = DOMAIN.COM server string = %h security = ads client signing = yes client use spnego = yes encrypt passwords = yes password server = pdc.domain.com kerberos method = system keytab dedicated keytab file = /etc/krb5.keytab idmap config * : backend = tdbsam preferred master = no dns proxy = no wins support = no inherit acls = Yes map acl inherit = Yes acl group control = yes load printers = no #debug level = 3 use sendfile = no #log level = 10 strict allocate = yes aio read size = 16384 aio write size = 16384 aio write behind = true socket options = TCP_NODELAY IPTOS_LOWDELAY
Samba does not perform reverse mapping for sssd users
So it was actually trivial, looking at the very last message from the bug report:Re: Bug#842226: dmesg: read kernel buffer failed: Operation not permittedPart of the changelog from the aforementioned kernel:security,printk: Enable SECURITY_DMESG_RESTRICT, preventing non-root users reading the kernel log by default (sysctl: kernel.dmesg_restrict)So the solution is simply to run once: % sudo sysctl kernel.dmesg_restrict=0 kernel.dmesg_restrict = 0Then your local user can start using dmesg again. This apply to any user, instead of a group which I initially assumed. Everything is back to what I wanted: % dmesg|wc 1307 11745 93652and % cat /dev/kmsg|head|wc 10 82 857And to make it persists across reboots, simply save it as conf file: $ echo kernel.dmesg_restrict = 0 | sudo tee -a /etc/sysctl.d/10-local.conf >/dev/null $ cat /etc/sysctl.d/10-local.conf kernel.dmesg_restrict = 0If you are on Ubuntu, for release 20.10 onwards there is already a line to persist this setting in /etc/sysctl.d/10-kernel-hardening.conf. After changing the file, to make the changes effective the user either needs to reboot or run sudo service procps restart .
Since recently Debian has changed the default behavior for dmesg and I cannot use it simply from my local user. % dmesg dmesg: read kernel buffer failed: Operation not permittedSame goes for: % cat /dev/kmsg cat: /dev/kmsg: Operation not permittedStarring at the bug tracker this lead to:dmesg: read kernel buffer failed: Operation not permittedHow do I change this behavior back to the previous one, where local user are allowed to use dmesg. I could not find a particular group for it (eg. sudoers or something like that).
dmesg: read kernel buffer failed: Permission denied
To make options such as this permanent you'll typically add them to the file /etc/sysctl.conf. You can see a full list of the options available using this command: $ sysctl -aExample $ sudo sysctl -a | head -5 kernel.sched_child_runs_first = 0 kernel.sched_min_granularity_ns = 6000000 kernel.sched_latency_ns = 18000000 kernel.sched_wakeup_granularity_ns = 3000000 kernel.sched_shares_ratelimit = 750000You can look for hugepage in the output like so: $ sudo sysctl -a | grep hugepage vm.nr_hugepages = 0 vm.nr_hugepages_mempolicy = 0 vm.hugepages_treat_as_movable = 0 vm.nr_overcommit_hugepages = 0It's not there? However looking through the output I did not see transparent_hugepage. Googling a bit more I did come across this Oracle page which discusses this very topic. The page is titled: Configuring HugePages for Oracle on Linux (x86-64). Specifically on that page they mention how to disable the hugepage feature. excerptThe preferred method to disable Transparent HugePages is to add "transparent_hugepage=never" to the kernel boot line in the "/etc/grub.conf" file. title Oracle Linux Server (2.6.39-400.24.1.el6uek.x86_64) root (hd0,0) kernel /vmlinuz-2.6.39-400.24.1.el6uek.x86_64 ro root=/dev/mapper/vg_ol6112-lv_root rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=uk LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 rd_NO_DM rd_LVM_LV=vg_ol6112/lv_swap rd_LVM_LV=vg_ol6112/lv_root rhgb quiet numa=off transparent_hugepage=never initrd /initramfs-2.6.39-400.24.1.el6uek.x86_64.imgThe server must be rebooted for this to take effect.Alternatively you can add the command to your /etc/rc.local file. if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fiI think I would go with the 2nd option, since the first will be at risk of getting unset when you upgrade from one kernel to the next. You can confirm that it worked with the following command after rebooting: $ cat /sys/kernel/mm/transparent_hugepage/enabled always madvise [never]
We are installing SAP HANA in a RAID machine. As part of the installation step, it is mentioned that, To disable the usage of transparent hugepages set the kernel settings at runtime with echo never > /sys/kernel/mm/transparent_hugepage/enabled So instead of runtime, if I wanted to make this a permanent change, should I add the above line inside /proc/vmstat file?
disable transparent hugepages
sysctl -w writes kernel parameter values to the corresponding keys under /proc/sys: sudo sysctl -w fs.inotify.max_user_watches=12288writes 12288 to /proc/sys/fs/inotify/max_user_watches. (It’s not equivalent, it’s exactly that; interested readers can strace it to see for themselves.) sysctl -ploads settings from a file, either /etc/sysctl.conf (the default), or whatever file is specified after -p. The difference between both approaches, beyond the different sources of the parameters and values they write, is that -w only changes the parameters until the next reboot, whereas values stored in /etc/sysctl.conf will be applied again every time the system boots. My usual approach is to use -w to test values, then once I’m sure the new settings are OK, write them to /etc/sysctl.conf or a file under /etc/sysctl.d (usually /etc/sysctl.d/local.conf). See the sysctl and sysctl.conf manual pages (man sysctl and man sysctl.conf on your system) for details.
I don't understand the best way to set fs.inotify.max_user_watches with sysctl. In fact, I don't understand much of what is happening here other than the fact that I need to set the number of files that can be watched by a particular process. I believe that I can see the max number of users by running this command: cat /proc/sys/fs/inotify/max_user_watchesMy understanding is that some people suggest changing /proc/sys/fs/inotify/max_user_watches by opening /etc/sysctl.conf in an editor and adding this to it: fs.inotify.max_user_watches=524288Then run sudo sysctl -p to -- presumably -- process the changes made to the file. Others suggest running commands like this: sudo sysctl -w fs.inotify.max_user_instances=1024 sudo sysctl -w fs.inotify.max_user_watches=12288I know that -w stands for write, but what is being written and where? Is it just that this command changes /proc/.../max_user_watches? Which of the two approaches outlined above is best? I understand that 524288 and 12288 are different numbers, but I don't understand the difference between the effect of running -p and -w.
How to set and understand fs.notify.max_user_watches
I'm going to supply a new answer to this question, since many Google search results lead here, and the internet has a lot of outdated information and misinformation about this. net.ipv{4,6}.conf.default.* @Martin von Wittich's correct about the behavior of default-- it's applied to new interfaces only. For a host's interfaces, the default setting will only apply when new devices are created, and host interfaces are traditionally only created at boot time. Therefore, if you simply change the default parameter, the value isn't applied to the host interfaces until the host is rebooted. The behavior is different for containers, Kubernetes and CNI. New container interfaces are created all the time. Therefore if you simply change the default parameter it will apply to new interfaces created by new containers, but not for existing container interfaces and not for host interfaces. This can be very confusing! net.ipv{4,6}.conf.all.* vs. net.ipv{4,6}.conf.<net device>.* The behavior of net.ipv{4,6}.conf.all.*, is different depending on the which parameter is being changed, as pointed out by @gaia & @odivlad. The real answer is in the Kernel's documentation and has changed over time (as with rp_filter, which is a popular parameter for multi-homed systems). Martin's answer above is was on the right track but is now out of date. The behavior for this feature is documented in the Kernel documentation, which you can find at https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt or https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/networking/ip-sysctl.txt?h=linux-4.15.y (Select your particular Kernel version in the upper right-hand corner). For example, the value for rp_filter will be MAXed (not ANDed as stated previously): The max value from conf/{all,interface}/rp_filter is used when doing source validation on the {interface}.arp_filter, on the other hand, is ORed: arp_filter for the interface will be enabled if at least one of conf/{all,interface}/arp_filter is set to TRUE, it will be disabled otherwiseBut what about accept_ra? Well, Kernel 4.15 documentation doesn't state the behavior in that case, and it's actually not allowed any more on a per-interface basis IIRC. It used to be allowed in Kernel 2.6 (CentOS 6, etc).
In sysctl, the /proc/sys/net/ipv[46]/conf/ keys have the following subkeys: all, default, and a key for each network interface. For example, on a machine with a single network interface eth0, it will look like this: iserv ~ # ll /proc/sys/net/ipv[46]/conf/ /proc/sys/net/ipv4/conf/: insgesamt 0 dr-xr-xr-x 0 root root 0 12. Sep 23:30 all/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 default/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 eth0/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 lo//proc/sys/net/ipv6/conf/: insgesamt 0 dr-xr-xr-x 0 root root 0 12. Sep 23:30 all/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 default/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 eth0/ dr-xr-xr-x 0 root root 0 12. Sep 23:30 lo/All the respective settings exist in each key separately. For example, if I want to disable IPv6 Router Advertisements with the accept_ra value, this value exists four times: iserv ~ # sysctl -a 2>/dev/null | grep "accept_ra " net.ipv6.conf.all.accept_ra = 1 net.ipv6.conf.default.accept_ra = 1 net.ipv6.conf.lo.accept_ra = 1 net.ipv6.conf.eth0.accept_ra = 1My question now is: which of these values do I need to change? I figured all (to change all existing interfaces) and default (to change all new interfaces that may appear later), but changing these still leaves the value at 1 for lo and eth0: iserv ~ # sysctl -w net.ipv6.conf.all.accept_ra=0 net.ipv6.conf.all.accept_ra = 0 iserv ~ # sysctl -w net.ipv6.conf.default.accept_ra=0 net.ipv6.conf.default.accept_ra = 0 iserv ~ # sysctl -a 2>/dev/null | grep "accept_ra " net.ipv6.conf.all.accept_ra = 0 net.ipv6.conf.default.accept_ra = 0 net.ipv6.conf.lo.accept_ra = 1 net.ipv6.conf.eth0.accept_ra = 1Will the machine now accept Router Advertisements on eth0, or will it not?
What is the difference between "all", "default" and "eth*" in /proc/sys/net/ipv[46]/conf/?
Checking the value of a sysctl variable is as easy as sysctl <variable name>and, by the way, setting a sysctl variable is as straightforward as sudo sysctl -w <variable name>=<value>but changes made this way will probably hold only till the next reboot. As to which of the config locations, /etc/sysctl.conf or /etc/sysctl.d/, takes precedence, here is what /etc/sysctl.d/README file says:End-users can use 60-*.conf and above, or use /etc/sysctl.conf directly, which overrides anything in this directory.After editing the config in any of the two locations, the changes can be applied with sudo sysctl -p
On my Ubuntu machine, in /etc/sysctl.conf file, I've got reverse path filtering options commented out by default like this: #net.ipv4.conf.default.rp_filter=1 #net.ipv4.conf.all.rp_filter=1but in /etc/sysctl.d/10-network-security.conf they are (again, by default) not commented out: net.ipv4.conf.default.rp_filter=1 net.ipv4.conf.all.rp_filter=1So is reverse path filtering enabled or not? Which of the configuration locations takes priority? How do I check the current values of these and other kernel options?
Finding out the values of kernel options related to sysctl.conf and sysctl.d
The ping command shows the address it resolved the name to. In this case it resolved to the IPv6 localhost address, ::1. On the other hand, 127.0.0.1 is an IPv4 address, so it explicitly makes ping use IPv4. The sysctl you used only affects IPv4 pings, so you get replies for ::1, but not for 127.0.0.1. The address you get from resolving localhost depends on how your DNS is resolver is set up. localhost is probably set in /etc/hosts, but in theory you could get it from an actual name server.As for how to drop IPv6 pings, you may need to look into ip6tables, as there doesn't seem to be a similar sysctl for IPv6. Or just disable IPv6 entirely, if you're not using it in your network. (Though of course that's not a very forward-looking idea, but doable if you're not currently using it anyway.)
After executing the following to disable ping replies: # sysctl net.ipv4.icmp_echo_ignore_all=1 # sysctl -pI obtain different results from pinging localhost vs. 127.0.0.1 # ping -c 3 localhost PING localhost(localhost (::1)) 56 data bytes 64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.029 ms 64 bytes from localhost (::1): icmp_seq=2 ttl=64 time=0.035 ms 64 bytes from localhost (::1): icmp_seq=3 ttl=64 time=0.101 ms--- localhost ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2042ms rtt min/avg/max/mdev = 0.047/0.072/0.101/0.022 msPinging 127.0.0.1 fails: ping -c 3 127.0.0.1 PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.--- 127.0.0.1 ping statistics --- 3 packets transmitted, 0 received, 100% packet loss, time 2032msWhy are these results different?
What is the difference between ping localhost and ping 127.0.0.1?
Sysctl settings are documented in Documentation/sysctl/*.txt in the kernel source tree. On Debian, install linux-doc to have the documentation in usr/share/doc/linux-doc-*/Documentation/ (most distributions have a similar package). From Documentation/sysctl/kernel.txt:The four values in printk denote: console_loglevel, default_message_loglevel, minimum_console_loglevel and default_console_loglevel respectively. These values influence printk() behavior when printing or logging error messages. See man 2 syslog for more info on the different loglevels.console_loglevel: messages with a higher priority than this will be printed to the console default_message_loglevel: messages without an explicit priority will be printed with this priority minimum_console_loglevel: minimum (highest) value to which console_loglevel can be set default_console_loglevel: default value for console_loglevelI don't find any clear prose explanation of what default_console_loglevel is used for. In the Linux kernel source, the kernel.printk sysctl sets console_printk. The default_console_loglevel field doesn't seem to be used anywhere.
Between Debian 5 and 6, the default suggested value for kernel.printk in /etc/sysctl.conf was changed from kernel.printk = 4 4 1 7 to kernel.printk = 3 4 1 3. I understand that the first value corresponds to what is going to the console. What are the next 3 values for? Do the numerical values have the same meaning as the syslog log levels? Or do they have different definitions? Am I missing some documentation in my searching, or is the only location to figure this out the kernel source.
Description of kernel.printk values
With no intention to compete with Marcus' complete answer. Just to explain what happened and justify that what you are noticing is not a bug. Default poolsize is hardcoded in drivers/char/random.c but something actually changed in 5.10.119 : Up to 5.10.118 : #define INPUT_POOL_SHIFT 12 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5)) ... static int sysctl_poolsize = INPUT_POOL_WORDS * 32;(2^(12-5))x32=4096 Under 5.10.119, poolsize appears computed differently : POOL_BITS = BLAKE2S_HASH_SIZE * 8 ... static int sysctl_poolsize = POOL_BITS;having BLAKE2S_HASH_SIZE = 32 as defined in include/crypto/blake2s.h 8x32=256 what you are noticing is not a bug… its : a feature ! BTW, it's just a default value, feel free to change it if you know it does not fit your needs.Note : This change, which concerns mainline since 5.17-rc1 was backported to 5.10 from 119 but also to the more recent LTS : 5.15 from 44. 5.4 does not seem concerned (yet ?) and of course, 5.16 will never be.As opportunely suggested by @TooTea in the comments, the reasons for the move can be read as part of the initial commit, in short :increased security (if the state of the pool leaks, its contents could be controlled and entirely zeroed out.) better performances (up to 225% on hight end cpu)This being achieved by replacing the 4096 LFSR by a direct call to the BLAKE2s.BLAKE2s outputs 256 bits, which should give us an appropriate amount of min-entropy accumulation, and a wide enough margin of collision resistance against active attacks.
After update to kernel 5.10.119, /proc/sys/kernel/random/entropy_avail became stuck to 256 and does not change when moving the mouse. It used to be greater than 3000. # cat /proc/sys/kernel/random/entropy_avail 256Also, /proc/sys/kernel/random/poolsize went down to 256. It used to be 4096. Is this a bug? Can you trust the new random number generator of this kernel with only 256 available entropy?
kernel 5.10.119 caused the values of /proc/sys/kernel/random/entropy_avail and poolsize to be 256
The difference is the scope, and how it's applied. Open file limits set via sysctls apply to the entire system, whereas limits set via /etc/security/limits.conf apply only to things that meet the criteria specified there. The other primary difference is that /etc/security/limits.conf limits are applied via ulimit, and thus can be changed more readily, while the sysctl limit is essentially setting up a memory allocation limit in the kernel itself. As a general rule, you almost always want to use /etc/security/limits.conf, even if you're setting global limits with the wildcard match there, as it is a bit more reliable, and things usually fail more gracefully when hit with ulimit restrictions than hitting kernel memory allocation limits.
I've read two separate ways of increasing the allowed open file count (I'm attempting to modify for root, if it matters). One way is to update the settings in /etc/security/limits.conf with something like: * soft nofile 500000* hard nofile 500000root soft nofile 500000root hard nofile 500000To make settings for the active shell, it looks like you can just do ulimit -n 500000, which wouldn't require a reboot or to logout/login, but may require restarting services (?).The other option is to update /etc/sysctl.conf: echo 'fs.file-max = 500000' >> /etc/sysctl.confTo make settings for the active shell, we can do sysctl -p, and verify with sysctl fs.file-max. So my question is, what's the difference? Is there one? I'm on Ubuntu 14.04.2 LTS
What's the difference between setting open file limits in /etc/sysctl.conf vs /etc/security/limits.conf?
Entries in procfs are managed by ad hoc code. The code that would set permissions and ownership on the files under /proc/sys (proc_sys_setattr) rejects changes of permissions and ownership with EPERM. So it isn't possible to change the permissions or ownership of these files, full stop. Such changes are not implemented, so being root doesn't help. When you try to write as a non-root user, you get a permission error. Even with sudo echo "/home/user/foo/core.%e.%p" > /proc/sys/kernel/core_pattern, you're trying to write as a non-root user: sudo runs echo as root, but the redirection happens in the shell from which sudo is executed, and that shell has no elevated privileges. With sudo bash -c '… >…', the redirection is performed in the bash instance which is launched by sudo and which runs as root, so the write succeeds. The reason only root must be allowed to set the kernel.core_pattern sysctl is that it allows a command to be specified and, since this is a global setting, this command could be executed by any user. This is in fact the case for all sysctl settings to various degrees: they're all global settings, so only root can change them. kernel.core_pattern is just a particularly dangerous case.
This question is associated with Where is core file with abrt-hook-cpp installed? . While I was trying to generate a core file for an intentionally-crashing program, at first core file generation seemed to be stymied by abrt-ccpp. So I tried to manually editing /proc/sys/kernel/core_pattern with vim: > sudo vim /proc/sys/kernel/core_patternWhen I tried to save the file, vim reported this error: "/proc/sys/kernel/core_pattern" E667: Fsync failedI thought this was a permission problem, so I tried to change permissions: > sudo chmod 666 /proc/sys/kernel/core_pattern chmod: changing permissions of '/proc/sys/kernel/core_pattern\': Operation not permittedFinally, based on this post, I tried this: >sudo bash -c 'echo /home/user/foo/core.%e.%p > /proc/sys/kernel/core_pattern'This worked. Based on the working solution, I also tried these, which failed: > echo "/home/user/foo/core.%e.%p" > /proc/sys/kernel/core_pattern -bash: /proc/sys/kernel/core_pattern: Permission denied > > sudo echo "/home/user/foo/core.%e.%p" > /proc/sys/kernel/core_pattern -bash: /proc/sys/kernel/core_pattern: Permission deniedQuestion: Why is it that editing, chmoding, and redirecting echo output to the file /proc/sys/kernel/core_pattern all failed, and only the noted invocation of sudo bash... was able to overwrite/edit the file? Question: Specifically, wrt the attempts to invoke sudo in the failed attempts above: why did they fail? I thought sudo executed the subsequent command with root privilege, which I thought let you do anything in Linux.
Why is editing core_pattern restricted?
Debian-based Linux Debian (and hence probably Ubuntu, too) has been known to ship a kernel with such a restriction of user_namespaces, and there the way to enable it was/is: sysctl -w kernel.unprivileged_userns_clone=1(Source: https://blog.mister-muffin.de/2015/10/25/unshare-without-superuser-privileges/.) Since kernel 5.10 (Debian 11/bullseye), Debian enables unprivileged user namespaces by default; if you find they're still disabled, also check the sysctl user.max_user_namespaces (which, unlike kernel.unprivileged_userns_clone, is not Debian-specific). ALT-Linux Specific ALT has such a restriction in kernel-image-std-def, too. Differently from Debian, it's called kernel.userns_restrict. Normally, it is 1 (i.e., "restricted"): $ cat /proc/sys/kernel/userns_restrict 1To enable this, echo 0 > /proc/sys/kernel/userns_restrict (or use sysctl as above, of course).
My Linux kernel must have been configured with user_namespaces when built, but their use is restricted after boot and has to be explicitly enabled. Which sysctl should I use? (If this was turned on, this would allow to run an isolation command like unshare --user --map-root-user --mount-proc --pid --fork, and then perform chroot without being root--a much anticipated feature of Linux.)
How to enable user_namespaces in the kernel? (For unprivileged `unshare`.)
According to this post titled: all vs. default in /proc/sys/net/ipv4/conf [message #3139]:When you change variables in the /proc/sys/net/ipv4/conf/all directory, the variable for all interfaces and default will be changed as well. When you change variables in /proc/sys/net/ipv4/conf/default, all future interfaces will have the value you specify. This should only affect machines that can add interfaces at run time, such as laptops with PCMCIA cards, or machines that create new interfaces via VPNs or PPP, for example.ReferencesLinux Firewall-related /proc Entries /proc/sys/net/ipv4/* Variables:
I want to enable reversed path filtering to prevent source ip spoofing on my server. I noticed that I have the following settings at current: net.ipv4.conf.all.rp_filter = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.lo.rp_filter = 0 net.ipv4.conf.p4p1.rp_filter = 1 net.ipv4.conf.eth0.rp_filter = 1The setting in all and the one in default are not the same. There are no explicit settings on my /etc/sysctl.conf file. I would like to what is the impact to the rest of the configurations between setting net.ipv4.conf.all.rp_filter = 1and net.ipv4.conf.default.rp_filter = 1Do I have to set both or just one of them?
What is the difference between all and default in kernel setting? [duplicate]
There is little relation between /proc/sys and /sys other than the fact that both are kernel interfaces and a coincidence of names. /proc/sys is an interface to sysctl, which are kernel configuration parameters. Reading or modifying /proc/sys/foo/bar is equivalent to getting or setting the foo.bar sysctl. Sysctl values are organized by semantic categories, they are not intrinsically related to the structure of the kernel. Many sysctl values are settings that are present on every Linux system regardless of what drivers or features are compiled in; some are related to optional features (e.g. certain network protocols) but never to specific hardware devices. /sys/module is, as the name indicates, an interface to kernel modules. Each directory corresponds to one kernel module. You can read, and sometimes modify, the parameters of the module foo by writing to /sys/module/foo/parameters/*. Components that are loaded in the kernel read their parameters from the kernel command line. These parameters cannot be set at runtime (at least not through an automatically-generated interface like /sys/module: the component can expose a custom interface for this).
I've been wondering for last few days how exactly does it work. We can set kernel runtimes parameters using sysctl or echo boolen 1> /proc/sys/module/exactParameter but in /sys/modules/module/parameters/parameter we can also set values. Are parameters for modules in /proc/sys/ related only to hard complied into kernel? or there could be parameters for Loadable Kernel Modules also? LKM after being loaded into running Kernel reveal their parameters in /sys/modules/module/paraeter/params. Does it mean, that there aren't parameters for modules compiled into Kernel? What is difference between both directories.
/proc/sys vs /sys/modules/mod/parameter
These are sysctl parameters. You can set them either by writing to /proc/sys/CATEGORY/ENTRY or by calling the sysctl command with the argument CATEGORY.ENTRY=VALUE. These settings affect the running kernel, they are not persistent. If you want to make these settings persistent, you need to set them at boot time. On Ubuntu, create a file in the directory /etc/sysctl.d called becko-vm-dirty.conf containing # Shrink the disk buffers to a more reasonable size. See http://lwn.net/Articles/572911/ vm.dirty_background_bytes = 16777216 vm.dirty_bytes = 50331648To revert the changes, write the old value back. There is no “restore defaults” command. Note that these parameters are a bit peculiar: there are also parameters called vm.dirty_ratio and vm.dirty_background_ratio, which control the same setting but express the size as a percentage of total memory instead of a number of bytes. For each of the two settings, whichever of ratio or bytes was set last takes precedence.
There's an issue with Ubuntu that hasn't been fixed yet, where the PC freezes or gets really slow whenever it is copying to an USB stick (see Why is my PC freezing while I'm copying a file to a pendrive?, http://lwn.net/Articles/572911/ and https://askubuntu.com/q/508108/234374). A workaround is to execute the following commands as root (see here for an explanation) as root: echo $((16*1024*1024)) > /proc/sys/vm/dirty_background_bytes echo $((48*1024*1024)) > /proc/sys/vm/dirty_bytesHow do I revert these changes? When I restart my PC, will it get rolled back to default values?
Pernicious USB-stick stall problem. Reverting workaround fix?
The authoritative source is the implementation in the kernel, so let’s look at that first. The panic entry in sysctl corresponds to a kernel variable called panic_timeout. This is a signed integer, used to control behaviour on panic as follows:if panic_timeout is strictly positive, the kernel waits after a panic, for panic_timeout seconds; if panic_timeout is non-zero, the kernel reboots after a panic (after waiting, if appropriate); if the kernel hasn’t rebooted, it prints a message and loops forever.So the manpage is correct, and the kernel’s own documentation was incomplete; but sysctl/kernel.rst now documents panic in more detail. This was fixed in version 5.7-rc1 of the kernel.
I always have /proc/sys/kernel/panic set up to 0. Looking at description of this option in kernel.org we can see:panic: The value in this file represents the number of seconds the kernel waits before rebooting on a panic. When you use the software watchdog, the recommended setting is 60.From here one can conclude that 0 is 0 seconds waiting before reboot - immediate reboot. But proc MAN page states the following:/proc/sys/kernel/panic This file gives read/write access to the kernel variable panic_timeout. If this is zero, the kernel will loop on a panic; if nonzero, it indicates that the kernel should autore‐ boot after this number of seconds. When you use the software watchdog device driver, the recommended setting is 60.Here 0 means antipodal thing - never reboot. So why such a trusted source gives such a misleading info? Or maybe the MAN page is inaccurate? P.S. just from a hint in panic_on_oops section (if you happen to read this) you can guess that MAN page is right. Or if you are technically skilled enough to investigate something in kernel source code.
Linux Kernel.org misleading about kernel panic /proc/sys/kernel/panic
You can’t open files under /proc/sys with tools which check their length; they appear as 0-byte files. To check the current value, run cat /proc/sys/vm/max_map_countor /sbin/sysctl vm.max_map_count
I tried looking into /proc/sys/vm/max_map_count file and it says 'empty' I have added a line vm.max_map_count=16777216 in etc/sysctl.config and want to see if changes are applied. I have certain problem with enlarging it being necessery to fix out of memory crashes in application and they still occur so i want to cross this one out.
How to display current vm.map_max_map_count value?
Sysctl parameters can be set via the kernel command-line starting with kernel version 5.8, thanks to Vlastimil Babka from SUSE. sysctl.*= [KNL] Set a sysctl parameter, right before loading the init process, as if the value was written to the respective /proc/sys/... file. Both '.' and '/' are recognized as separators. Unrecognized parameters and invalid values are reported in the kernel log. Sysctls registered later by a loaded module cannot be set this way. Example: sysctl.vm.swappiness=40
Is it possible to set Linux kernel sysctl settings (those usually set in /etc/sysctl.d) using kernel command line (those visible in /proc/cmdline)? (Using grub config file /etc/default/grub variable GRUB_CMDLINE_LINUX="...".)
How to set sysctl using kernel command line parameter?
on Linux, you'd do something like sudo sysctl -w net.ipv4.ip_local_port_range="60000 61000" instruction for changing ephemeral port range on other unices can be found for example at http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
There's a binary that I need to run which uses bind with a port argument of zero, to get a random free port from the system. Is there a way I can constrain the range of ports the kernel is allowed to pick from?
How to limit range of random port sockets?
You need to execute: sysctl -w net.ipv4.conf.all.arp_filter=1This can be useful reading: Multiple network interfaces and ARP flux
I have a server that has some VMs, but the VMs can't communicate properly with the server because the server has several interfaces, and it responds on the wrong one. Q: We know that there is a kernel parameter that can ensure that ARP responses will come only from that interface where the request went. What is that sysctl setting? Server is Debian machine.
sysctl parameter for correct ARP response
Look at Documentation/sysctl/vm.txt:dirty_ratio Contains, as a percentage of total available memory that contains free pages and reclaimable pages, the number of pages at which a process which is generating disk writes will itself start writing out dirty data. The total available memory is not equal to total system memory.The available memory is calculated in global_dirtyable_memory(). It is equal to the amount of free memory plus the page cache. It does not include swappable pages (i.e. anonymous memory allocations, memory which is not backed by a file). This behaviour applies since Linux 3.14 (2014). Before this change, swappable pages were included in the global_dirtyable_memory() total. Example statistics while running the dd command: $ while true; do grep -E '^(Dirty:|Writeback:|MemFree:|Cached:)' /proc/meminfo | tr '\n' ' '; echo; sleep 1; done MemFree: 1793676 kB Cached: 1280812 kB Dirty: 4 kB Writeback: 0 kB MemFree: 1240728 kB Cached: 1826644 kB Dirty: 386128 kB Writeback: 67608 kB MemFree: 1079700 kB Cached: 1983696 kB Dirty: 319812 kB Writeback: 143536 kB MemFree: 937772 kB Cached: 2121424 kB Dirty: 312048 kB Writeback: 112520 kB MemFree: 755776 kB Cached: 2298276 kB Dirty: 389828 kB Writeback: 68408 kB ... MemFree: 136376 kB Cached: 2984308 kB Dirty: 485332 kB Writeback: 51300 kB MemFree: 101340 kB Cached: 3028996 kB Dirty: 450176 kB Writeback: 119348 kB MemFree: 122304 kB Cached: 3021836 kB Dirty: 552620 kB Writeback: 8484 kB MemFree: 101016 kB Cached: 3053628 kB Dirty: 501128 kB Writeback: 61028 kBThe last line shows about 3,150,000 kB "available" memory, and a total of 562,000 kB data either being written back or waiting for writeback. That makes it 17.8%. Although it seemed the proportion fluctuated above and below that level, and was more often closer to 15%. EDIT: although these figures look closer, please do not trust this method. It is still not the right calculation and it could give very wrong results. See the followup here.I found this the hard way: I noticed there is a tracepoint in balance_dirty_pages(), which can be used for "analyzing the dynamics of the throttling algorithms". So I used perf: $ sudo perf list '*balance_dirty_pages'List of pre-defined events (to be used in -e): writeback:balance_dirty_pages [Tracepoint event] ... $ sudo perf record -e writeback:balance_dirty_pages dd if=/dev/zero of=~/test bs=1M count=2000 $ sudo perf scriptIt showed that dirty (measured in 4096-byte pages) was lower than I expected, because setpoint was low. I traced the code; it meant there must be a similarly low value for freerun in the tracepoint definition, which is set to (thresh + bg_thresh) / 2 ... and worked my way back to global_dirtyable_memory().
I have been testing Linux 4.18.16-200.fc28.x86_64. My system has 7.7G total RAM, according to free -h. I have default values for the vm.dirty* sysctl's. dirty_background_ratio is 10, and dirty_ratio is 20. Based on everything I've read, I expect Linux to begin writeout of dirty cache when it reaches 10% of RAM: 0.77G. And buffered write() calls should block when dirty cache reaches 20% of RAM: 1.54G. I ran dd if=/dev/zero of=~/test bs=1M count=2000 and watched the dirty field in atop. While the dd command was running, the dirty value settled at around 0.5G. This is significantly less than the dirty background threshold (0.77G)! How can this be? What am I missing? dirty_expire_centisecs is 3000, so I don't think that can be the cause. I even tried lowering dirty_expire_centisecs to 100, and dirty_writeback_centisecs to 10, to see if that was limiting dirty. This did not change the result. I initially wrote these observations as part of this investigation: Why were "USB-stick stall" problems reported in 2013? Why wasn't this problem solved by the existing "No-I/O dirty throttling" code?I understand that half-way between the two thresholds - 15% = 1.155G - write() calls start being throttled (delayed) on a curve. But no delay is added when underneath this ceiling; the processes generating dirty pages are allowed "free run". As I understand it, the throttling aims to keep the dirty cache somewhere at or above 15%, and prevent hitting the 20% hard limit. It does not provide a guarantee for every situation. But I'm testing a simple case with one dd command; I think it should simply ratelimit the write() calls to match the writeout speed achieved by the device. (There is not a simple guarantee because there are some complex exceptions. For example, the throttle code limits the delay it will impose to a maximum of 200ms. But not if the target ratelimit for the process is less than one page per second; in that case it will apply a strict ratelimit.)Documentation/sysctl/vm.txt -- Linux v4.18 No-I/O dirty throttling -- 2011 LWN.net.(dirty_background_ratio + dirty_ratio)/2 dirty data in total ... is an amount of dirty data when we start to throttle processes -- Jan Kara, 2013Users will notice that the applications will get throttled once crossing the global (background + dirty)/2=15% threshold, and then balanced around 17.5%. Before patch, the behavior is to just throttle it at 20% dirtyable memory -- commit 143dfe8611a6, "writeback: IO-less balance_dirty_pages()"The memory-management subsystem will, by default, try to limit dirty pages to a maximum of 15% of the memory on the system. There is a "magical function" called balance_dirty_pages() that will, if need be, throttle processes dirtying a lot of pages in order to match the rate at which pages are being dirtied and the rate at which they can be cleaned." -- Writeback and control groups, 2015 LWN.net.balance_dirty_pages() in Linux 4.18.16.
Writeback cache (`dirty`) seems to be limited to even less than dirty_background_ratio. What is it being limited by? How is this limit calculated?
As far as I know, you can use modprobe to adjust parameters only when the feature in question has been compiled as a module - and you're loading the module in the first place. For setting module parameters persistently, you'll have the /etc/modprobe.d directory. (Generally you should leave /usr/lib/modprobe.d for distribution's default settings - any files in there may get overwritten by package updates.) If the module in question has been built into the main kernel, then you must use the <module_name>.<parameter_name>=<value> syntax, typically as a boot option. If the parameter in question is available as a sysctl setting, then you can use the sysctl -w command to adjust it too. All the available sysctl parameters are presented under /proc/sys: for example, kernel.domainname is at /proc/sys/kernel/domainname. Not all module parameters are available as sysctls, but some might be. If a loadable module has already been loaded, and you wish to change its parameters immediately without unloading it, then you can write the new value to /sys/module/<module_name>/parameters/<parameter_name>. If the module cannot accept dynamic reconfiguration for that parameter, the file will be read-only. At least on my system, kernel.domainname is a sysctl parameter for the main kernel, and trying to change it with modprobe won't work: # sysctl kernel.domainname kernel.domainname = (none) # modprobe kernel domainname="example.com" modprobe: FATAL: Module kernel not found in directory /lib/modules/<kernel_version> # sysctl kernel.domainname kernel.domainname = (none)In a nutshell: If you are unsure, first look into /proc/sys or the output of sysctl -a: if the parameter you're looking for is not there, it is not a sysctl parameter and is probably a module parameter (or the module that would provide the sysctl is not currently loaded, in which case it's better to set the value as a module parameter anyway - trying to set a sysctl belonging to a module that is not currently loaded will just produce an error). Then, find out which module the parameter belongs to. If the module is built into the kernel, you'll probably have to use a boot option; if it is loadable with modprobe (i.e. the respective <module>.ko file exists somewhere in the /lib/modules/<kernel version>/ directory tree), then you can use modprobe and/or /etc/modprobe.d/.
We know that sysctl command can change kernel parameters with : # sysctl -w kernel.domainname="example.com"or by directly editing the file in /proc/sys directory. And for persistent changes, the parameters must be written to /etc/sysctl.d/<moduleName>.conf files as: # echo kernel.domainname="example.com" > /etc/sysctl.d/domainname.confHowever, we can also change the kernel parameters using the modprobe command: # modprobe kernel domainname="example.com"And then there's the modprobe.conf file in the /etc/modprobe.d directories, which is present in multiple locations: /etc/modprobe.d and /usr/lib/modprobe.d. It contains multiple .conf files, and the options can be provided in the appropriate conf file for the module as: options kernel domainname="example.com"So, what's the difference between each of these methods? Which method should be used under what specific circumstances?
Difference between modprobe and sysctl -w in terms of setting system parameters?
The configuration has long moved to /etc/sysctl.d/* You can create individual files, e.g. cat /etc/sysctl.d/swappiness.confvm.swappiness=10As for the sysctl -a output - you're seeing the current kernel values.
I want to change two values using sysctl. One is the sysctl vm.swappiness=10 and the other, sysctl kernel.sysrq=1. However, when I run sysctl -p, it tells me sysctl: cannot open "/etc/sysctl.conf": No such file or directory, but sysctl -a returns this. So, I want to ask where is my system storing sysctl config?
If /etc/sysctl.conf doesn't exist, where is my sysctl storing configs?
In systemd operating systems like Fedora, loading these settings is done with the systemd-sysctl commmand, run by the systemd-sysctl service. Your problem is that you have put the settings in the wrong configuration file. systemd-sysctl does not read /etc/sysctl.conf. It reads a whole bunch of *.conf files in (amongst other places) the /etc/sysctl.d directory. You should create such a file and put your settings there. Further readingLennart Poettering et al. (2016). systemd-sysctl. systemd manual pages. Freedesktop.org. Lennart Poettering et al. (2016). sysctl.d. systemd manual pages. Freedesktop.org.
I am running Fedora 27 with kernel 4.14.5 and have a problem that /etc/sysctl.conf is not being loaded upon boot. If I run: sudo sysctl -pafter boot, my settings are loaded and everything works fine. What do I need to do to enable the loading of /etc/sysctl.conf or what alternatives are there to load it?
Fedora /etc/sysctl.conf not loaded upon boot
What @Tomasz says it's true: those are kernel parameters, so they are "unique"! Anyway, you can achieve some result with that limit...in the OP, @Osqui doesn't say users are simultaneously logged in...by sketching out a script executed when users login/logout using the sysctl command
I know there's *.conf file in /usr/lib/sysctl.d and/or /etc/sysctl.d folders ready to establish kernel parameters on boot. But they are general; what I want is to customize some of these parameters (say, net.ipv4.icmp_echo_ignore_all) depending on the user who is in, but I want per-user kernel parameters. Is it possible or what I'm saying is a complete silliness?
Customize sysctl parameters by user
I don’t think there is any such official documentation. sysctl entries are handled by procps and systemd; but neither projects’ documentation address how entries are processed within the same configuration file. The short version is that the last entry in sysctl.conf wins, even when other files are present (in /etc/sysctl.d or elsewhere), regardless of which system is used to load the settings. procps To understand how procps processes entries, we need to look at the source code for sysctl. This shows that later entries are processed without knowledge of earlier entries, so the last one wins (look at the Preload function). When multiple configuration files are given on the command line, these are processed in order, as described in the man page:Using this option will mean arguments to sysctl are files, which are read in the order they are specified.Things get a little more complex with the --system option, but at least that’s documented:Load settings from all system configuration files. Files are read from directories in the following list in given order from top to bottom. Once a file of a given filename is loaded, any file of the same name in subsequent directories is ignored./run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.confThe documentation isn’t quite complete. As mentioned above, entries within a given file are applied in order, and overwrite any value given to the same setting previously. In addition, looking at the PreloadSystem function show that files are processed in name order, and that /etc/sysctl.conf is processed unconditionnally (i.e. an identically-named file in an earlier directory doesn’t override it). systemd systemd has its own sysctl handler, which is documented in the sysctl.d manpage; that has a section on precedence:Configuration files are read from directories in /etc/, /run/, and /usr/lib/, in order of precedence. Each configuration file in these configuration directories shall be named in the style of filename.conf. Files in /etc/ override files with the same name in /run/ and /usr/lib/. Files in /run/ override files with the same name in /usr/lib/. […] All configuration files are sorted by their filename in lexicographic order, regardless of which of the directories they reside in. If multiple files specify the same option, the entry in the file with the lexicographically latest name will take precedence. It is recommended to prefix all filenames with a two-digit number and a dash, to simplify the ordering of the files.Again, later entries within a single configuration file override earlier entries.
Where can I find the official documentation that sysctl.conf is last match based? So, there are two entries in the /etc/sysctl.conf file: vm.swappiness=10 vm.swappiness=11Which will win? The last one? What happens if there are files in the /etc/sysctl.d directory?
Is sysctl.conf last match?
In both cases, you’re trying to interact with the kernel. Any Linux environment running on WSL isn’t running a Linux kernel, it’s running on the Windows kernel; so anything tied to the Linux kernel (including modules and system controls) won’t work. In the IPv6 case, you need to configure the network using Windows’ tools.
When I run lsmod or sudo lsmod, I get an error that says: libkmod: ERROR ../libkmod/libkmod-module.c:1655 kmod_module_new_from_loaded: could not open /proc/modules: No such file or directory Error: could not get list of modules: No such file or directoryI searched on a lot of forums but am unable to find a solution for this. I'm running Debian on Windows Subsystem for Linux. I was recently also trying to edit the sysctl.conf file for the purpose of disabling ipv6. I had added the following lines: net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1And when I tried sudo sysctl -p, it returned this error: sysctl: cannot stat /proc/sys/net/ipv6/conf/all/disable_ipv6: No such file or directory sysctl: cannot stat /proc/sys/net/ipv6/conf/default/disable_ipv6: No such file or directory sysctl: cannot stat /proc/sys/net/ipv6/conf/lo/disable_ipv6: No such file or directoryI'm not sure if the above 2 errors are connected. I was trying to run Linux shell on Windows. Any solution to the problem?
lsmod gives error: "could not get list of modules" on Debian running on WSL
There's no automatic database relating sysctl variables to modules. You can search the module binary and hope that the variable name isn't found in other strings (this one isn't). Search for the last part, i.e. bridge-nf-call-iptables —the full string isn't present in the binary, it's constructed dynamically. grep -rl bridge-nf-call-iptables /lib/modules/`uname -r`Alternatively, you can check the documentation —but it doesn't always tell you, and in this case it doesn't say. So you're left with the source code. First look for the string (again, only the last part); in recent kernels it's in net/bridge/br_netfilter_hooks.c. Now check the makefile in the same directory to see how this source file is built. The relevant line is br_netfilter-y := br_netfilter_hooks.owhich means that if the br_netfilter module is built then it contains the code from br_netfilter_hooks.c, thus the br_netfilter module is the one you need.
This is on the Linux OS. I see that on some machines the net.bridge.bridge-nf-call-iptables variable doesn't exist until I modprobe the br_netfilter filter. I also see that there are some machines where the bridge module is loaded and that itself brings in this variable. Is there a way to know which module I should load in order to get a particular variable ?
Kernel module for net.bridge.bridge-nf-call-iptables
You can use sysctl to set some of the kernel parameters, specifically the ones under /proc/sys. These can be set in the file /etc/sysctl.conf or added to a single file (the preferred method on some distro's such as Fedora) in the directory /etc/sysctl.d. On distros that have this directory it's meant for customization's. excerpt from sysctl's man page sysctl - configure kernel parameters at runtimeExample You can get a partial list of what kernel parameters are currently set using this command: $ sudo sysctl -a | head -5 abi.vsyscall32 = 1 debug.exception-trace = 1 debug.kprobes-optimization = 1 dev.cdrom.autoclose = 1 dev.cdrom.autoeject = 0Making a change /etc/sysctl.conf Simply add rules to the file sysctl.conf. # sysctl.conf sample # kernel.domainname = example.com ; this one has a space which will be written to the sysctl! kernel.modprobe = /sbin/mod probeYou can also use the sysctl.conf command line to make edits to this file without having to edit it directly. $ sysctl -w kernel.domainname="example.com"After making any changes be sure to make them active. $ sysctl -p/etc/sysctl.d To add your override of this parameter simply put it in a file named similarly to the files that are already present in the /etc/sysctl.d directory. $ ls -l /etc/sysctl.d total 40 -rw-r--r-- 1 root root 77 Jul 16 2012 10-console-messages.conf -rw-r--r-- 1 root root 490 Jul 16 2012 10-ipv6-privacy.conf -rw-r--r-- 1 root root 726 Jul 16 2012 10-kernel-hardening.conf -rw-r--r-- 1 root root 1184 Jul 16 2012 10-magic-sysrq.conf -rw-r--r-- 1 root root 509 Jul 16 2012 10-network-security.conf ...In a file named something like 99-myparam.conf. $ more 10-console-messages.conf # the following stops low-level messages on console kernel.printk = 4 4 1 7Where the name of the parameter is on the left, and it's corresponding value is on the right. See sysctl's man page for more details.
What's the prescribed way to set Linux kernel runtime parameters? I've seen sometimes that people will set these in files such as /etc/rc.local. Is this really the right way to do this?
What's the right way to set Linux kernel runtime parameters?
No. swapoff -a completely turns off swapping. swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
Is setting in /etc/sysctl.conf: vm.swappiness=0equivalent (except that it's persistent) to running swapoff -a, *in Linux kernels >= 3.5?*in earlier kernel versions, 0 meant 'no swapping until out of memory'.
Is `vm.swapiness=0` equivalent to `swapoff -a` (in kernel >= 3.5)
The number at the beginning of the name of configuration files is used as an easily readable way to sort them, with the aim of defining the order of precedence among the entries they contain. From man 5 sysctl.d1 (emphasis mine):CONFIGURATION DIRECTORIES AND PRECEDENCE ... All configuration files are sorted by their filename in lexicographic order, regardless of which of the directories they reside in. If multiple files specify the same option, the entry in the file with the lexicographically latest name will take precedence. It is recommended to prefix all filenames with a two-digit number and a dash, to simplify the ordering of the files.1 The man page for sysctl.d is shipped as part of the systemd package and the quoted text comes from version 244.3 on Arch Linux. The wording differs to some extent, but not significantly (for the purpose of this Q/A), from both the version currently available at The Linux man-pages project and the version you can find on freedesktop.org.
The sysctl utility allows a Linux admin to query and modify kernel parameters in runtime. For example, to change the swappiness of a Linux system to 0, we can:echo 0 > /proc/sys/vm/swappinessOr we can use sysctl:sysctl -w vm.swappiness=0To make the value persistent, Archwiki suggests to write vm.swappiness=0 to /etc/sysctl.d/99-swappiness.conf file. For persistent silent boot, Archwiki suggests to write kernel.printk = 3 3 3 3 to /etc/sysctl.d/20-quiet-printk.conf Similarly I have a 99-sysrq.conf on my system which works without the number as well.Archwiki has a sysctl page which mentions the importance of the number:Note: From version 207 and 21x, systemd only applies settings from /etc/sysctl.d/*.conf and /usr/lib/sysctl.d/*.conf. Ifyou had customized /etc/sysctl.conf, you need to rename it as /etc/sysctl.d/99-sysctl.conf. Ifyou had e.g. /etc/sysctl.d/foo, you need to rename it to /etc/sysctl.d/foo.conf.What does the number in 99-swappiness.conf and 20-quiet-printk.conf denote here?
What does the number in sysctl configuration file denote?
So one of the big things about learning to Unix is reading the bloody man page: I'm not just being a get off my lawn grumpy old man, there REALLY IS valuable information in there. In this case:DESCRIPTION sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl support in Linux. You can use sysctl to both read and write sysctl data.So we can: $sudo sysctl -a | grep kernel.perf_event_max_sample_rate kernel.perf_event_max_sample_rate = 50000 sysctl: reading key "net.ipv6.conf.all.stable_secret" sysctl: reading key "net.ipv6.conf.default.stable_secret" sysctl: reading key "net.ipv6.conf.enp3s0.stable_secret" sysctl: reading key "net.ipv6.conf.lo.stable_secret" sysctl: reading key "net.ipv6.conf.wlp1s0.stable_secret"By reading the manpage we learn that -a is "display all values currently available", but we also can see:SYNOPSIS sysctl [options] [variable[=value]] [...] sysctl -p [file or regexp] [...]which means we can shorten the above command to: $ sudo sysctl kernel.perf_event_max_sample_rate kernel.perf_event_max_sample_rate = 50000 Or we can: $ more /proc/sys/kernel/perf_event_max_sample_rate 50000So, TL;DR:Yes, you can write a script to log this variable every few minutes, but if it's going to show up in the logs when it changes, why would you?It would probably be more efficient to read the value right out of /proc/sys/kernel/perf_event_max_sample_rate than to use sysctl, and it would be more efficient to ask for the specific value from sysctl than to use grep.
I saw in my syslog kernel.perf_event_max_sample_rate get changed. I was wondering if I could write a quick script to log this variable every few minutes. Currently it is: sysctl -a | grep kernel.perf_event_max_sample_rateIn the man page sysctl sayssysctl - configure kernel parameters at runtimeDoes that mean that my script would get the parameter as it was set when the kernel starts? Would it pick up changes?
View current kernel parameters?
As revealed in the comments, there’s a pcie_aspm=offline in one of the files which sysctl -p reads. This causes sysctl to attempt to write to /proc/sys/pcie_aspm; if that doesn’t exist (and it won’t, it’s not a valid sysctl entry, it’s a kernel boot parameter), you’ll get the error shown in your question.
when we run the sysctl -p on our rhel 7.2 server1 we get sysctl -p fs.file-max = 500000 vm.swappiness = 10 vm.vfs_cache_pressure = 50 sysctl: cannot stat /proc/sys/pcie_aspm: No such file or directory net.core.somaxconn = 1024# ls /proc/sys/pcie_aspm ls: cannot access /proc/sys/pcie_aspm: No such file or directorybut when we run the sysctl -p on other server2 as we get good results without error as sysctl -p fs.file-max = 500000 vm.swappiness = 10 vm.vfs_cache_pressure = 50 net.core.somaxconn = 1024the file - /proc/sys/pcie_aspm not exist on this server also ( server2 ) so why sysctl -p failed on server1?
sysctl -p failed on /proc/sys/pcie_aspm
For the Linux sysctl, from procps-ng, this was reported a year ago, and the manpage fixed:The w flag is not needed for key=val type options but only forces all options to be that format.Now the manpage reads:-w, --write Use this option when all arguments prescribe a key to be set.
sysctl has this -w switch. Is it really needed? I tried to do: sysctl vm.max_map_count=262144And it seems to have worked out.
Is -w option of sysctl really needed when changing kernel parameters?
Try all and default: # sysctl -w "net.ipv4.conf.all.rp_filter=0" # sysctl -w "net.ipv4.conf.default.rp_filter=0"This is explained in the Kernel documentation: conf/default/*: Change the interface-specific default settings. conf/all/*: Change all the interface-specific settings.However note that putting a new value in all doesn't change the value you read from the interface, but it only gets computed and used internally. See this email for more details.
How can i change a parameter for all interfaces in systemd ? For example: sysctl -w "net.ipv4.conf.eth0.rp_filter=0" sysctl -w "net.ipv4.conf.eth1.rp_filter=0"How can change it for all interfaces ?
Change sysctl parameters for all interfaces
If your kernel uses modules for iptables, which is the case in most distributions, you can blacklist the base module; create a file named, for example, /etc/modprobe.d/iptables-blacklist.conf, containing install ip_tables /bin/falseYou can block other variants in a similar fashion (ip6_tables, ebtables, nf_tables etc.), or block x_tables to block ebtables, iptables, ip6tables and arptables in one go (but not nftables).
I'm famillar with iptables -F and other features of iptables. I need to disable iptables from kernel, of course I prefer to disable from sysctl instead of recompiling the kernel.
How to disable iptables from kernel
The "ratios" refer to the size of the dirty page cache aka write-back cache, as a percentage of MemFree + Cached. They are not a percentage of MemTotal - this was what confused me in the above question.No. This description is still inaccurate. Cached includes all files in tmpfs, and other Shmem allocations. They are counted because they are implemented using the page cache. However they are not cache of any persistent storage. They can't just be dropped. tmpfs pages can be swapped, but swappable pages are not included in the calculation. I had 500-600MB of Shmem. This was about the right amount, to explain why limit / 0.20 was lower than I had expected, when I tried looking the tracepoint again (see answer to previous question). Also Cached excludes Buffers, which can be a surprisingly large amount on certain setups. I think I should look carefully at the implementation of global_dirtyable_pages() for my kernel version, and use the more low-level counters exposed in /proc/vmstat. Or perhaps focus on using the tracepoint instead.
In a previous question and answer, I showed an experiment about dirty_ratio. Writeback cache (`dirty`) seems to be limited to even less than dirty_background_ratio. What is it being limited by? How is this limit calculated? I thought I solved the question, by correcting my understanding of the dirty ratio calculation. But I repeated the experiment just now, and the write-back cache was limited to lower than I saw before. I can't work this out, what could be limiting it? I have default values for the vm.dirty* sysctl's. dirty_background_ratio is 10, and dirty_ratio is 20. The "ratios" refer to the size of the dirty page cache aka write-back cache, as a percentage of MemFree + Cached. They are not a percentage of MemTotal - this was what confused me in the above question. These ratios mean that reaching 10% causes background writeback to start, and 20% is the maximum size of the write-back cache. Additionally, I understand the write-back cache is limited by "I/O-less dirty throttling". When the write-back cache rises above 15%, processes which generate dirty pages e.g. with write() are "throttled". That is, the kernel causes the process to sleep inside the write() call. So the kernel can control the size of the write-back cache, by controlling the length of the sleeps. For references, see the answer to my previous question. But my observed "ratio" seems to stay distinctly lower than the 15% throttling threshold. There must be some factor I am missing! Why is this happening? In my previous test I saw values around 15-17.5% instead. My kernel is Linux 4.18.16-200.fc28.x86_64. The test is as follows: I ran dd if=/dev/zero of=~/test bs=1M status=progress. And at the same time, I monitored the achieved dirty ratio. I interrupted the dd command after 15GB. $ while true; do grep -E '^(Dirty:|Writeback:|MemFree:|Cached:)' /proc/meminfo | tr '\n' ' '; echo; sleep 1; done ... MemFree: 139852 kB Cached: 3443460 kB Dirty: 300240 kB Writeback: 135280 kB MemFree: 145932 kB Cached: 3437220 kB Dirty: 319588 kB Writeback: 112080 kB MemFree: 134324 kB Cached: 3448776 kB Dirty: 237612 kB Writeback: 160528 kB MemFree: 134012 kB Cached: 3449004 kB Dirty: 169064 kB Writeback: 143256 kB MemFree: 133760 kB Cached: 3449024 kB Dirty: 105484 kB Writeback: 119968 kB MemFree: 133584 kB Cached: 3449032 kB Dirty: 49068 kB Writeback: 104412 kB MemFree: 134712 kB Cached: 3449116 kB Dirty: 80 kB Writeback: 78740 kB MemFree: 135448 kB Cached: 3449116 kB Dirty: 8 kB Writeback: 0 kBFor example, the first line in the quoted output: avail = 139852 + 3443460 = 3583312 dirty = 300240 + 135280 = 435520 ratio = 435520 / 3583312 = 0.122...I found one thing that was limiting it, but not enough to see these results. I had been experimenting with setting /sys/class/bdi/*max_ratio. The test results in the question are from running with max_ratio = 1. Repeating the above test with max_ratio = 100, I can achieve a higher dirty ratio e.g. 0.142: MemFree: 122936 kB Cached: 3012244 kB Dirty: 333224 kB Writeback: 13532 kBThe write test needs to be quite long to observe this reliably, e.g. 8GB. This test takes about 100 seconds. I am using a spinning hard disk. I tried testing with 4GB, and I only saw a dirty ratio of 0.129: MemFree: 118388 kB Cached: 2982720 kB Dirty: 249020 kB Writeback: 151556 kBAs I say, this surprises me. I have an expert source from 2013, saying that dd should have "free run" to generate dirty pages until the system hits a dirty ratio of 0.15. It is explicitly talking about max_ratio.
Writeback cache (`dirty`) seems to be limited below the expected threshold where throttling starts. What is it being limited by?
Some time during kernel boot - when the MM subsystem is initialized - it calculates 3% of the remaining free memory. If that is more than 8MiB, the value is set to 8MiB. Hence we say the value is set to the minimum of the two. This is a one-time initialization; it is never re-calculated. https://elixir.bootlin.com/linux/v5.0/source/mm/mmap.c#L3666 The value of the sysctl is a number. It is not a number of bytes; it is a number of "KiB". 1 KiB is 1024 bytes. It is the closest number to 1000, that is a convenient power of 2. RAM chips are built in powers of 2. (Also, we can multiply or divide powers of 2 using a fast binary shift operation).
Many of the kernel parameters have default values assigned. But some of them aren't really clear. I'm reading the proc manual and in the case of admin_reserve_kbytes we can read the following:The default value in this file is the minimum of [3% of free pages, 8MiB] expressed as KiB.There are other similar default values, so what does this mean?
What's the default value of the admin_reserve_kbytes kernel parameter?
You can use the --reinstall flag to apt-get apt-get --reinstall install procps
In the process of trying to fix an issue, I accidentally deleted /sbin/sysctl when I was intending to delete /etc/sysctl.conf. When I run sysctl I get the error that says The program 'sysctl' is currently not installed. You can install it by typing: sudo apt-get install procpsWhen I try both install and upgrade it says procps is already the newest version. I've also tried removing procps and reinstalling it but I get this error: Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation:The following packages have unmet dependencies: libegl1-mesa : Depends: libgbm1 (>= 7.11~1) but it is not going to be installed E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.Is there a way for me to just get the sysctl file from this package? Is there a fix for the error when I try to remove procps so that I can make it work that way? If it matters, I'm on Linux Mint 17.3 Rosa with Ubuntu 14.04
Restore part of a package that was accidentally deleted
sysctl is an administrative tool which provides access to values in the /proc/sys virtual file system (see also How to set and understand fs.notify.max_user_watches). You can use it to see the current value of a setting: sysctl fs.inotify.max_user_watchesand to change the value: sysctl fs.inotify.max_user_watches=524288systemd-sysctl is a systemd service which loads sysctl settings from a number of files during boot. You shouldn’t ever need to invoke or manipulate it directly. The two tools are complementary: sysctl allows you to try a setting temporarily (the changes it makes don’t persist over reboots), and once you’ve decided on an appropriate value, writing it to a file in /etc/sysctl.d will ensure that systemd-sysctl sets it during boot. Again, see How to set and understand fs.notify.max_user_watches.
What is the main difference between systemd-sysctl vs sysctl and when to use either? Both are present in my debian based system.
Diffence between `systemd-sysctl` and `sysctl`
Setting ip_forwarding to 1 enables the kernel to route packets. Basically your host will become a router. Setting ip_redirect to zero disables the kernel to sending or receiving icmp-redirects, which will occur if some host (or this host) finds a better route for a packet.
What are the differences between sysctl variables net.inet.ip.forwarding and net.inet.ip.redirect?
Differences between forwarding and redirect in net.inet.ip
If, by "sudoless", you mean you want to be able to just write dmesg or such on the command line, then the simplest solution would be to make a script that calls /bin/dmesg through sudo, and configure sudo to let that happen without asking for a password. So, something like this: echo 'username ALL = NOPASSWD:/bin/dmesg ' >> /etc/sudoers cat <<'EOF' > ./dmesg #!/bin/sh sudo /bin/dmesg "$@" EOF chmod +x ./dmesgand then put ./dmesg somewhere in your path. This works as long as you don't have some other program that needs to be able to read the kernel message buffer directly, without going through /bin/dmesg. But then, setting /bin/dmesg setuid would have the same limitation. Running it via sudo is probably safer than simply running it setuid. As an aside, changing the permissions on /dev/kmsg doesn't work, even though dmesg tries to read it. It falls back to the syslog(2) system call.If that's not enough, you might be able to do this with capabilities. The dmesg_restrict sysctl restricts reading the log to processes with CAP_SYSLOG, so we just need to arrange for that to be set. So, something like this: # cp /bin/dmesg /bin/dmesg.capable #chown .adm /bin/dmesg.capable #chmod 710 /bin/dmesg.capable #setcap cap_syslog=ep /bin/dmesg.capableUsers in the adm group should now be able to use /bin/dmesg.capable to view the log. Though note that capabilities are notorious in that many of them provide ways to circumvent the rest of the access control systems, though granting just CAP_SYSLOG is probably better than running dmesg as full root.Other options that spring to mind are SELinux, seccomp and just plain old patching the kernel to allow reading the log by a certain group.
I understand that, for security reasons (like address randomization), it makes some sense to not let every user be able to read the kernel's dmesg. Linux allows one to restrict dmesg to the root user using: sysctl -w kernel.dmesg_restrict = 1. That sysctl forces everyone who wants to use dmesg to prepend sudo, which is a problem for me.¹ I would like something in between. I want some user accounts on my machines to have sudoless access to dmesg, but not daemons like apache or non-users like www-data. Ideally, dmesg access would be restricted to a certain group (say, adm). What is the cleanest² way to do this?Footnotes: ¹ While I like sudo in concept, I believe it should be a four-letter word: used judiciously by the wise as a perfect epithet for the rare occasions when nothing else would suffice. Unfortunately, I see people using sudo for many mundane tasks nowadays without thinking twice. Getting people into the habit of overusing sudo is a worse security problem than potential address leaks from the kernel. ² I mention "cleanest", because I suspect that some solutions, like chmod 4750 /bin/dmesg, might have potentially hairy security implications.Update: I've accepted Ikkachu's setcap solution, but I hope that in future versions of Linux there will be a cleaner, more general answer. Perhaps a third sysctl setting for dmesg_restrict that is between 0 (everybody) and 1 (root only), that would let sysadmins specify trusted groups.
Can I restrict dmesg to a group?
These settings don’t have the same effect:threads-max limits the number of processes which can be instantiated simultaneously pid_max limits the identifier assigned to processesthreads-max limits the amount of memory that can end up allocated to task_struct instances. pid_max determines when pids roll around (if ever). Constraining pid_max doesn’t have an effect on memory consumption (as far as I’m aware, unless lots of pids end up stored as text), and can end up affecting performance since finding a new pid is harder once pid_max has been reached. A lower pid_max also increases the likelihood of pid reuse within a given time period.
I understand the difference between /proc/sys/kernel/pid_max and /proc/sys/kernel/threads-max. There's a good explanation at the answer to Understanding the differences between pid_max, ulimit -u and thread_max:/proc/sys/kernel/pid_max has nothing to do with the maximum number of processes that can be run at any given time. It is, in fact, the maximum numerical PROCESS IDENTIFIER than can be assigned by the kernel. In the Linux kernel, a process and a thread are one and the same. They're handled the same way by the kernel. They both occupy a slot in the task_struct data structure. A thread, by common terminology, is in Linux a process that shares resources with another process (they will also share a thread group ID). A thread in the Linux kernel is largely a conceptual construct as far as the scheduler is concerned. Now that you understand that the kernel largely does not differentiate between a thread and a process, it should make more sense that /proc/sys/kernel/threads-max is actually the maximum number of elements contained in the data structure task_struct. Which is the data structure that contains the list of processes, or as they can be called, tasks.However, effectively, both limit the maximum number of concurrent threads on a host. This number will be - to my understanding - the minimum of pid_max and threads-max. So why are both needed? I understand that the default value pid_max is based on the number of possible CPUs of the machine while the default of threads-max is derived from the number of pages. But since both have the same effect, couldn't Linux just have one value that would be the minimum of both?
Why does Linux needs both pid_max and threads-max?
But is there a way for me to find this kernel documentation offline? Is it a package that I'd need to install?Yes, most distributions provide the kernel documentation for their kernel in a package. On Debian, this is linux-doc, which is a meta-package pulling in the default kernel’s documentation for whichever release you’re using (version-specific packages are available too, *e.g. linux-doc-4.19). On RHEL, CentOS etc. it’s kernel-doc. You’ll find the file you’re looking for in this case in /usr/share/doc/kernel-doc-*/Documentation/sysctl/kernel.txt on RHEL. In newer versions the file has been converted to ReSTructured text and can be found in .../Documentation/admin-guide/sysctl/kernel.rst (which is also where you can find the current kernel sysctl documentation on the kernel web site). Checking the packaged version gives you a better chance to get the documentation matching your running kernel; in some cases though the current documentation is more accurate, even for older kernels, and this is the case here — I improved the documentation following Linux Kernel.org misleading about kernel panic /proc/sys/kernel/panic, and that ended up in version 5.7 of the kernel.
The NOTES section of $ man 5 sysctl.conf states: The description of individual parameters can be found in the kernel documentation. But is there a way for me to find this kernel documentation offline? Is it a package that I'd need to install? For example, I came across the kernel.panic parameter, which on my system is set to 0 by default. Looking it up online here, it's described to be: panic:The value in this file represents the number of seconds the kernel waits before rebooting on a panic. When you use the software watchdog, the recommended setting is 60.But there is no reasonable way I'd guessed that the 0 there referred to 0 seconds till auto reboot without searching it up online.
Where to get offline documentation/descriptions of individual sysctl kernel tunable parameters?
The kworker "process" that you show is a kernel thread and not a normal process. There is no userspace portion for it and thus no syscalls. Even if it worked it couldn't possibly show anything. On top of everything else, I guess that tracing kernel threads (under whatever fictional scenario one can imagine) would most probably freeze the system.
As root, I try to attach strace to a running kworker process, without success. root@rasal# whoami root root@rasal:/# cat /proc/sys/kernel/yama/ptrace_scope 0 root@rasal:/# ps ax | grep kworker 1030 ? S< 0:00 [kworker/u17:0] root@rasal:/# strace -fp 1030 strace: attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.confThe etc/sysctl.d/10-ptrace.conf file simply states: A PTRACE scope of "0" is the more permissive mode.This is exactly what I have, see above. Is there any reason why this should fail? Or is this a bug?
Why am I unable to attach `strace` to a kworker process?
Availability of hyperthreading is managed from BIOS/EFI. What OpenBSD do is to put offline the processor(s)/thread(s). So You should do it in BIOS/EFI by disabling hyperthreading option.
It is well known that OpenBSD disables hyper-threading by default. However, htop shows 16 CPUs: 8 online and 8 offline, which takes extra space on the screen and is not very informative.Moreover, sysctl also sees 16 logical CPUs. This doesn't make sense to me: with hyperthreading disabled, it's an 8-core 8-thread processor, so I should see 8 physical/logical CPUs. $ sysctl hw hw.machine=amd64 hw.model=AMD Ryzen 7 5800H with Radeon Graphics hw.ncpu=16 hw.byteorder=1234 hw.pagesize=4096 hw.disknames=sd0:6d1abdce154d2fc8 hw.diskcount=1 hw.sensors.cpu0.frequency0=3900000000.00 Hz hw.sensors.cpu2.frequency0=3900000000.00 Hz hw.sensors.cpu4.frequency0=3900000000.00 Hz hw.sensors.cpu6.frequency0=3900000000.00 Hz hw.sensors.cpu8.frequency0=3900000000.00 Hz hw.sensors.cpu10.frequency0=3900000000.00 Hz hw.sensors.cpu12.frequency0=3900000000.00 Hz hw.sensors.cpu14.frequency0=3900000000.00 Hz hw.sensors.ksmn0.temp0=83.12 degC (Tctl) hw.sensors.it0.temp0=83.00 degC hw.sensors.it0.temp1=49.00 degC hw.sensors.it0.temp2=200.00 degC hw.sensors.it0.fan0=0 RPM hw.sensors.it0.fan1=3835 RPM hw.sensors.it0.fan2=2986 RPM hw.sensors.it0.volt0=1.74 VDC (VCORE_A) hw.sensors.it0.volt1=1.62 VDC (VCORE_B) hw.sensors.it0.volt2=2.67 VDC (+3.3V) hw.sensors.it0.volt3=3.71 VDC (+5V) hw.sensors.it0.volt4=10.69 VDC (+12V) hw.sensors.it0.volt5=-3.24 VDC (-12V) hw.sensors.it0.volt6=0.57 VDC (-5V) hw.sensors.it0.volt7=3.68 VDC (+5VSB) hw.sensors.it0.volt8=2.16 VDC (VBAT) hw.cpuspeed=3200 hw.setperf=100 hw.vendor=AZW hw.product=SER hw.version=Default string hw.serialno=A58003LH80340 hw.uuid=00020003-0004-0005-0006-000700080009 hw.physmem=13840232448 hw.usermem=13840216064 hw.ncpufound=16 hw.allowpowerdown=1 hw.perfpolicy=manual hw.smt=0 hw.ncpuonline=8 hw.power=1 hw.ucomnames=How do I disable logical processors, so that each "CPU" is a physical processor?
How to disable logical processors in OpenBSD?
The main factor here is that memcpy is handled by the C library, or even directly by the C compiler, whereas write is a system call, handled by the kernel. So your memcpy runs in-process, possibly without even the (tiny) overhead of a function call. write, on the other hand, has all the overhead of a system call. In your test especially, since the write size is small, the cost of the copy itself is probably dwarfed by the cost of the system call. Even with your larger tests, it’s likely that the system call cost is still the main factor. To reduce the weight of the system calls, try comparing with even larger sizes, changing the dirty ratio configurations if necessary, or writing to a tmpfs to avoid the cost of writing to a disk. You might also want to disable KPTI and other mitigations which increase the cost of system calls, and perhaps look into io_uring. To get a better idea of the work involved in handling a write, you can trace the appropriate system call, __x64_sys_write on x86-64; this will show the call chain and time spent, e.g. 9) | __x64_sys_write() { 9) | ksys_write() { 9) | __fdget_pos() { 9) | __fget_light() { 9) 0.465 us | __fget_files(); 9) 0.943 us | } 9) 1.155 us | } 9) | vfs_write() { 9) | rw_verify_area() { 9) | security_file_permission() { 9) | selinux_file_permission() { 9) | __inode_security_revalidate() { 9) | _cond_resched() { 9) 0.034 us | rcu_all_qs(); 9) 0.241 us | } 9) 0.649 us | } 9) | file_has_perm() { 9) 0.034 us | bpf_fd_pass(); 9) | inode_has_perm() { 9) 0.133 us | avc_has_perm(); 9) 0.376 us | } 9) 0.808 us | } 9) 2.126 us | } 9) 0.032 us | bpf_lsm_file_permission(); 9) 2.616 us | } 9) 2.815 us | } 9) | __vfs_write() { 9) | new_sync_write() { 9) | pipe_write() { 9) | mutex_lock() { 9) | _cond_resched() { 9) 0.034 us | rcu_all_qs(); 9) 0.236 us | } 9) 0.566 us | } 9) | _cond_resched() { 9) 0.036 us | rcu_all_qs(); 9) 0.232 us | } 9) 0.036 us | mutex_unlock(); 9) | __wake_up_sync_key() { 9) | __wake_up_common_lock() { 9) 0.036 us | _raw_spin_lock_irqsave(); 9) | __wake_up_common() { 9) | pollwake() { 9) | default_wake_function() { 9) | try_to_wake_up() { 9) 0.178 us | _raw_spin_lock_irqsave(); 9) | select_task_rq_fair() { 9) 0.033 us | available_idle_cpu(); 9) 0.032 us | available_idle_cpu(); 9) 0.040 us | cpus_share_cache(); 9) 0.058 us | available_idle_cpu(); 9) 1.061 us | } 9) 0.036 us | ttwu_queue_wakelist(); 9) 0.036 us | _raw_spin_lock(); 9) 0.079 us | update_rq_clock(); 9) | ttwu_do_activate() { 9) | enqueue_task_fair() { 9) | enqueue_entity() { 9) 0.040 us | update_curr(); 9) 0.088 us | __update_load_avg_se(); 9) 0.070 us | __update_load_avg_cfs_rq(); 9) 0.032 us | update_cfs_group(); 9) 0.055 us | __enqueue_entity(); 9) 1.347 us | } 9) | enqueue_entity() { 9) 0.038 us | update_curr(); 9) 0.077 us | __update_load_avg_se(); 9) 0.050 us | __update_load_avg_cfs_rq(); 9) | update_cfs_group() { 9) 0.047 us | reweight_entity(); 9) 0.289 us | } 9) 0.035 us | __enqueue_entity(); 9) 1.469 us | } 9) 0.033 us | hrtick_update(); 9) 3.546 us | } 9) | ttwu_do_wakeup() { 9) | check_preempt_curr() { 9) 0.046 us | resched_curr(); 9) 0.279 us | } 9) 0.671 us | } 9) 4.653 us | } 9) 0.038 us | _raw_spin_unlock_irqrestore(); 9) 7.458 us | } 9) 7.652 us | } 9) 7.924 us | } 9) 8.865 us | } 9) 0.045 us | _raw_spin_unlock_irqrestore(); 9) 9.501 us | } 9) 9.703 us | } 9) 0.033 us | kill_fasync(); 9) 0.055 us | __sb_start_write(); 9) | file_update_time() { 9) | current_time() { 9) 0.037 us | ktime_get_coarse_real_ts64(); 9) 0.039 us | timestamp_truncate(); 9) 0.454 us | } 9) | __mnt_want_write_file() { 9) 0.057 us | __mnt_want_write(); 9) 0.289 us | } 9) | generic_update_time() { 9) 0.089 us | __mark_inode_dirty(); 9) 0.321 us | } 9) 0.039 us | __mnt_drop_write_file(); 9) 1.904 us | } 9) 0.037 us | __sb_end_write(); 9) + 14.315 us | } 9) + 14.620 us | } 9) + 14.840 us | } 9) 0.166 us | __fsnotify_parent(); 9) 0.095 us | fsnotify(); 9) + 18.702 us | } 9) | fput() { 9) 0.035 us | fput_many(); 9) 0.238 us | } 9) + 20.668 us | } 9) + 20.907 us | }This is a rather extreme example but it illustrates that the system call can end up doing an awful lot more than copying memory.
I am benchmarking the write performance in the case that Linux writes the data to the page cache without throttling the process or syncing the data to the disk. The simple experiment I am doing looks like the following: long size = 1024; int fd = open ("file", O_CREAT | O_RDWR | O_TRUNC, ...); char *buffer = (char *) malloc (size) **start_time = time.now ();** write (fd, buffer, size); **end_time = time.now ();** close (fd); printf ("write duration %d\n", end_time - start_time);Here I expect to effectively observe the memory bandwidth since the data is only copied to the page cache of the OS, and nothing is synced to the disk. Also, the OS has not started with the background flushes or throttling the process, since, the dirty rate is way lower than the background_dirty_ratio. Though, when I compare it to the memory bandwidth (memcpy cost of the same size), it is way more expensive than a memcpy: char *buffer1 = (char *) malloc (size) char *buffer2 = (char *) malloc (size) **start_time = time.now ();** memcpy (buffer1, buffer2, size); **end_time = time.now ();** printf ("memcpy duration %d\n", end_time - start_time);For instance on my system (Linux kernel version 4.2, CentOS), I see a memcpy bandwidth of almost 60GB/s, and the write bandwidth is almost 2GB/s. To my understanding, when write system call is invoked, it merely copies the data in the page cache (in memory) and returns as soon as the copy is done. So I expect to see a bandwidth near to memory bandwidth. I also tested the same experiment with larger data (before the OS starts to throttle the process) to mitigate the cost of making the system call. But still, I see almost the same results. Does anyone know why I am not observing the memory bandwidth when performing write on the page cache?
Linux Page Cache Performance versus memcpy
You can enable user namespaces like this, sysctl -w kernel.unprivileged_userns_clone=1And you can have it persist after reboot in Debian by running this, echo "kernel.unprivileged_userns_clone=1" >> /etc/sysctl.conf
When I run podman I get, $ podman info cannot clone: Operation not permitted user namespaces are not enabled in /proc/sys/kernel/unprivileged_userns_clone Error: cannot re-exec processHow can I enable user namespaces and have them persist after reboot? I am using Debian.
How can I enable user namespaces and have it persist after reboot?
Looks like you need to enable pluginsync: In puppet.conf: [main] pluginsync = true
Running CentOS 5.5 with Puppet 0.25.5 I have installed and am using the puppet-sysctl module. However the following error occurs: //linux_tuning/Sysctl::Value[net.core.rmem_default] Sysctl[net.core.rmem_default] (err): Failed to retrieve current state of resource: No ability to determine if sysctl exists //linux_tuning/Sysctl::Value[net.core.rmem_default]/Exec[exec_sysctl_net.core.rmem_default] (notice): Dependency sysctl[net.core.rmem_default] has 1 failures //linux_tuning/Sysctl::Value[net.core.rmem_default]/Exec[exec_sysctl_net.core.rmem_default] (warning): Skipping because of failed dependenciessysctl is installed. And /etc/sysctl.conf is present. Anyone have an idea as to why this is happening and have an idea as to how to fix it? An excerpt from puppet.conf: [main] vardir = /var/lib/puppet logdir = /var/log/puppet rundir = /var/run/puppet ssldir = $vardir/ssl runinterval = 21600
Puppet problem with sysctl
I don't know why under Linux the speed test is using only one CPU for my Mikrotik but I was able to fix the slowdown by upgrading to 7.x (at minimum >= 7.2) to be able to use fast-track under VLAN filtering at the bridge level.
I cannot explain this, I will start by listing these speed test results this one is the linux host running mxlinux latest versionthis one is the windows 10 running inside vmware on the same computerI'm trying to figure out why it's THAT bad on linux I have tried the web interface, I'm getting the same kind of result every single time I have tried different distribution (live usb) same thing I have tried different browser, again same thing I don't think it should matter but just in case; I have a gigabyte x570 aorus pro with amd 3900x, 32 gig ram and linux is installed on an nvme I wonder if it's something on my side or speedtest is that bad with linux or auto tunning of sysctl with tcp is the cause or some weird/obscure setting with the kernel. I don't know if it matter too, my router is a mikrotik hap ac2, the same cable is used on the linux host and the windows 10 vm I'm open to any suggestion, tweak, etc. it's really bad for no reason. edit 1 I forgot to add that from my router with what is called btest, I was able to get the same speed and even faster than on windows 10 with a public server I have a NAS connected to the same router, I ran iperf and I'm getting my full 1gb speed between linux and my NAS Edit 2Edit 3 I think I found the culprit. with mikrotik router, there is a packet sniffer that show a lot of information and one of them is which cpu is used. the mikrotik that I have got 4 cpu under windows, it use multiple cpu while under linux it use only one cpu during the speedtest something under linux is making it use only one cpu Edit 4 look like I need to upgrade the firmware of my router to the latest version 7.x I am using latest version of 6.x and they added a feature in 7.x where I can lower cpu usage while using vlan. I quickly tested and it look like it solve my issue, getting same speed under linux as windows screenshot and more, I will look at this more this weekend because I tested with a bare bone configuration, not my real one. Edit 5 so it look like I had to upgrade to latest version 7.x to be able to get the maximum speed under linux... Edit 6 I had to use the new feature fast track that work with vlan-filtering since 7.2
strange issue, worst network speed and worst ping latency on linux
In most cases it shouldn’t make any difference either way, at least at the end of an input string. In all cases, only written data is processed — the kernel knows how long the supplied buffer is (1 byte for 1 with no newline, 2 for 1 with a newline) and will only process that many bytes. sysctl entries using the standard sysctl-handling functions handle newlines explicitly: in strings, they terminate input, in vectors, they separate entries (most numeric values end up being handled as vectors, e.g. /proc/sys/net/ipv4/ip_forward). This is in addition to reaching the end of user input, which always ends processing. So the following all produce the same result: $ echo 1 > /proc/sys/net/ipv4/ip_forward $ printf 1 > /proc/sys/net/ipv4/ip_forward $ printf '1\n0\n' > /proc/sys/net/ipv4/ip_forwardThus the answer toDoes writing a newline character into a sysctl (/proc/sys) file have any effect?is yes: it indicates the end of a value. That indication may or may not add information compared to the end of the input as a whole; that depends on the context (specifically, whether the value being written is a vector or not). Code handling output for sysctl, i.e. producing the text that’s read when something reads from a sysctl entry, always adds a terminating newline, as might be expected. The sysctl utility always writes a newline, so it’s safe to assume that in most cases this will continue to be valid. (I haven’t checked all the sysctl handlers so there may be some specific handlers which object to newlines.)
Today I ran into some code that's writing a newline character explicitly into a sysctl file. See moby/docker source code. My first thought is that the author has diligently copied the shell's behaviour into go despite the newline being redundant. But then I started to look for documentation on the subject and found it a really hard one to find information on either way. I haven't managed to come up with anything so far.When writing sysctl files in /proc/sys/ many of the values are integers written in ASCII. For example, to toggle something on or off you have to write 1 or 0 as text into a file. Often the advice here on U&L and on blogs etc. is to do this in the shell using echo. For example turning on IPv4 forwarding: echo 1 > /proc/sys/net/ipv4/ip_forwardBut this advice does something subtly different to its stated goal. It doesn't write a single byte 0x31 to the file. It writes two: 0x31 0x0A also known as 1\n. I had always assumed the newline (0x0A) was simply ignored by the kernel.Does writing a newline character into a sysctl file (eg /proc/sys/net/ipv4/ip_forward) have any effect? References welcome even if they are links to source code.
Does writing a newline character into a sysctl (/proc/sys) file have any effect?
Your observation that sysctl predominantly contains system-wide parameters is apt. It also follows somewhat from the name sysctl (which suggests SYStem ConTroL), and the man page's description of "sysctl - get or set kernel state." Some BSD systems do offer optional procfs filesystem support which can be mounted under /proc, such as FreeBSD: # mount -t procfs procfs /procThis provides some of the functionality, but is perhaps most often used for compatibility purposes when running Linux binaries in emulation mode, rather than for definitive inquiries into the run-time statistics of specific native BSD processes. Unfortunately, OS X doesn't support procfs filesystems, to my knowledge. And more generally, BSD systems don't use /proc, so the answer of what to use to replace a particular /proc-based query varies depending on what the specific query is. Given the recent edit to your post, you may find this command helpful to display memory usage for a specific process: $ sudo vmmap $$
I've been using /proc/self for a long time to read process-related information like /proc/self/maps etc. However, on some UNIX variants, like macOS, the procfs filesystem is not implemented; but as this link states, it should be possible to obtain similar information using sysctl. Reading output from sysctl -a, I find that information is not directly associated to any specific process, but instead relates to the system or kernel. So, how can I use sysctl to read the information, normally present in /proc/self on Linux distributions, on UNIX variants like macOS? I want to e.g. get /proc/self/maps on macOS.
How to use sysctl on UNIX variants, e.g. macOS, to read information normally found in /proc/self on Linux?
Edits to the file /etc/sysctl.conf normally will only affect the system upon reboot unless you run by hand: sudo sysctl -pIf you want to set a particular kernel variable at run time, do: sudo sysctl -w kernel.shmmni=4096If you want to see all the kernel variables, do: sysctl -a
I am going to install oracle database 12c on oracle linux 7.5. In the process, I have to edit following kernel parameters and set values. fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 536870912 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048586Documentation says I should edit /etc/sysctl.conf file. When I run cat /etc/sysctl.conf to read current contents it displays following message. # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5)When I try to edit with root user in vi, it says sysctl.conf is read only. even when I override with '!', changes does not apply and modify the parameters.
editing sysctl.conf on oracle linux 7.5
You are redirecting the stderr of the grep to /dev/null but the stderr messages are coming from sysctl. Try sudo sysctl -a --ignore 2>/dev/null | grep -i max_map_count
I want to grep a particular kernel setting as follows $ sudo sysctl -a --ignore | grep -i max_map_count 2>/dev/null sysctl: reading key "net.ipv6.conf.all.stable_secret" sysctl: reading key "net.ipv6.conf.default.stable_secret" sysctl: reading key "net.ipv6.conf.docker0.stable_secret" sysctl: reading key "net.ipv6.conf.enp2s0.stable_secret" sysctl: reading key "net.ipv6.conf.lo.stable_secret" sysctl: reading key "net.ipv6.conf.wlp3s0.stable_secret" vm.max_map_count = 262144Since I am both ignoring info about unknown keys (i.e. the --ignore option) and redirecting potential error output to /dev/null, what are these reading jey lines printed?
sysctl command returning info not asked about
The effective (soft) 1024 descriptor ulimit is a total for the process, including descriptors that are used for non-connection purposes. Apparently that process is using about 100 descriptors for other things, leaving only 921 for connections. lsof -p <process-id> will show you how the descriptors are being used. To allow more descriptors, raise the soft limit before launching the process. If you're running it from bash, that would be: ulimit -Sn 2048to raise it to 2048 for future commands. To raise the soft limit to whatever the allowed maximum (the hard limit, in this case 4096) is you can do: ulimit -Sn unlimitedIf you only want the elevated limit to apply to one command, and not to other future commands, raise the limit in a subshell: (ulimit -Sn 2048 ; c1000k)If you want to go beyond your current hard limit of 4096 descriptors then you can run your test from a user account that has sufficient privilege to raise the hard limit, or you can change the initial hard and soft ulimit values set at login time for your user account by modifying /etc/security/limits.conf or (better) by adding files in /etc/security.d. See the comments in the limits.conf file or run man limits.conf for details.
I ran c1000k on my CentOS 7.2 machine and it told me connections: 921 error: Too many open filesBecause of this I changed my /etc/sysctl.conf to contain this: fs.file-max = 2097152But even after a reboot I still run into the same limit. ulimit -Sn and ulimit -Hn print 1024 respectively 4096.
Less than 1000 possible connections although I updated sysctl
As one can lookup in Documentation/networking/nf_conntrack-sysctl.txt, this variable is not really a sysctl variable to tweak system behavior, but to read-only variable telling you something about kernel state, in this case: nf_conntrack_count - INTEGER (read-only) Number of currently allocated flow entries.This number changes over time, since the number of allocated flow entries (connections, the conntrack subsystem is tracking at the moment) changes. You could try it out by establishing a bunch of connections to some server and look how the value changes.
I have found that the value of net.netfilter.nf_conntrack_count variable change every time i reboot the system. Did any one have an explanation for that?
Sysctl parameter change after every reboot
According to the documentation, and to my quick reading of the source code, a backslash has no special meaning here. Since \* is not a range, does not start with any of the recognized special characters @%, and is not the exact string *, the domain is interpreted as a user name. Note that the user name is \*, not *. This is just a mistake in the file, possibly a bug in a script used to generate the file. The intent was presumably to write * (meaning all users) instead of \*.
/etc/security/limits.conf looks like this #<domain> <type> <item> <value> ##* soft core 0 #* hard rss 10000 #@student hard nproc 20 #@faculty soft nproc 20 #@faculty hard nproc 50 #ftp hard nproc 0 #@student - maxlogins 4# End of file \* soft nofile 20000 \* hard nofile 22000as I remember the backslash should not set before * soft nofile 20000 so I not sure if backslash meaning is to ignore the line or just ignore the star (*) wildcard ?
what is the meaning of backslash in /etc/security/limits.conf
There is no equivalent. I suspect the mention of sysctl comes from a misconception and wasn’t actually tested. multicast_snooping is a device attribute exposed through sysfs, typically mounted on /sys, whereas sysctl accesses sysctl variables exposed in /proc/sys. It is technically possible for the same setting to be exposed both through sysfs and sysctl, but that’s not the case here.
I found this answer that says I can enable/disable multicast snooping by writing to /sys/devices/virtual/net/br-lan/bridge/multicast_snooping "or in sysctl.conf". I'd like to make it permanent but I can't work out what this value is called in sysctl.conf. How do I figure out what multicast_snooping is called in sysctl.conf so that I can make the change persist over boot on this old OpenWRT device?
How to find sysctl.conf option name from /sys/devices path?
as per man lsofAn open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream or a network file (Internet socket, NFS file or UNIX domain socket.) A specific file or all the files in a file system may be selected by path.So number of line in lsof is likely much more than actual file descriptor. See this reated question : https://serverfault.com/questions/485262/number-of-file-descriptors-different-between-proc-sys-fs-file-nr-and-proc-pi
As I spawn several processes in a loop, I hit the maximum number of open files handles and the for loop breaks. When I count the open file handles using lsof I get: $ lsof | wc -l 1464377However checking fs.file-nr returns: $ sysctl fs.file-nr fs.file-nr = 35328 0 6553201I expected the first number to be 1464377. I have a couple of questions:What's the difference between the output of lsof (1464377) and file-nr (35328). The maximum seems to be 6553201, which looks rather arbitrary. What's the maximum value for this number?
Open file handles
During a boot sysctl settings are initially set to default values hardcoded into the kernel. You most likely don't want to revert to these, as system specific settings are loaded from the various system configuration files by a sysctl init script, in a manner similar to the command you executed, except not limited to settings matching a certain pattern. Unless you've actually edited some settings in any of the configuration files, or configured certain sysctl settings directly via sysctl, chances are that you've not actually changed any of the settings by reloading the configuration. If you've actually set some settings directly with sysctl, without recording the corresponding change to a particular configuration file, the change will be lost at reboot. The command sysctl -a displays all available sysctl values.
While trying to read some kernel parameters, I think I have mistakenly set some instead: # sysctl --system -r ^net.*tcp * Applying /usr/lib/sysctl.d/00-system.conf ... * Applying /usr/lib/sysctl.d/50-default.conf ... kernel.sysrq = 16 kernel.core_uses_pid = 1 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 fs.protected_hardlinks = 1 fs.protected_symlinks = 1 * Applying /etc/sysctl.d/99-sysctl.conf ... * Applying /etc/sysctl.conf ...Now, is there a way to undo those changes?
How to undo kernel settings?
Because sysctl.conf uses dots as filesystem path separators, you have to use / in place of actual dots. Yes, it's weird like that. net.ipv6.conf.Ethernet1/200.disable_ipv6 = 0But you can actually use / as the separator, too: net/ipv6/conf/Ethernet1.200/disable_ipv6 = 0I would honestly suggest not disabling IPv6 by default; then the problem would be avoided.
I tried thefollowing: sysctl -w net.ipv6.conf.Ethernet1.200.disable_ipv6=0, but it gave following error: sysctl: cannot stat /proc/sys/net/ipv6/conf/Ethernet1/200/disable_ipv6: No such file or directoryIt should have ideally tried to change in /proc/sys/net/ipv6/conf/Ethernet1.200/disable_ipv6 which it is not I have used echo 0 > /proc/sys/net/ipv6/conf/Ethernet1.200/disable_ipv6, but I need some Linux command that does the same.
How to enable IPv6 on subinterface in Linux using sysctl?
From man page:-p Load in sysctl settings from the file(s) specified or /etc/sysctl.conf if none given. Specifying - as filename means reading data from standard input.YES. the new watch limits are applied to services that are currently running
I'm increasing the watch limit on my RHEL 7 server and I'd like my changes to take effect without having to reboot. I've updated the /etc/sysctl.conf file so that the changes will be permanent. If I run sysctl -p after updating the systcl.conf file, will the new watch limits be applied to services that are currently running or will they have to be restarted?
do you have to restart services after running sysctl -p?
I think your surmise is correct, they are inherited from the parent namespace. This seems similar to how processes clone themselves using the fork() system call, then any desired changes have to be applied by the clone, using the normal system calls. (Including replacing the current program with a completely different one, using exec(). fork()+exec() being how e.g. the shell runs other programs, although this magic is not usually visible to the user). None of the options to the underlying unshare system call change this. So I'd say the answer to your question is no. http://man7.org/linux/man-pages/man2/unshare.2.htmlOh... that wasn't even an analogy! Look at the option flags:CLONE_NEWNET (since Linux 2.6.24) This flag has the same effect as the clone(2) CLONE_NEWNET flag. Unshare the network namespace, so that the calling process is moved into a new network namespace which is not shared with any previously existing process. Use of CLONE_NEWNET requires the CAP_SYS_ADMIN capability.clone() basically means fork().Since version 2.3.3, rather than invoking the kernel's fork() system call, the glibc fork() wrapper that is provided as part of the NPTL threading implementation invokes clone(2) with flags that provide the same effect as the traditional system call. (A call to fork() is equivalent to a call to clone(2) specifying flags as just SIGCHLD.)
What are the default kernel parameters, when creating a new network namespace? Is there a way to override them upon creation? I think they are inherited by the parent process. An example using unshare: > /sbin/sysctl -a --pattern 'net.ipv4.conf.all.forwarding' net.ipv4.conf.all.forwarding = 1 > unshare -n > /sbin/sysctl -a --pattern 'net.ipv4.conf.all.forwarding' net.ipv4.conf.all.forwarding = 1
Default kernel parameters on new network namespaces
I agree with thrig, this does look like a bug. Writing directly to procfs is an obvious workaround. If you need to use the sysctl utility, another workaround is to add a newline: sysctl -w net.ipv4.ip_local_reserved_ports=" "A trailing newline has no effect on most if not all sysctl settings.
I'm trying to assign an empty string to a system setting, but it fails: [root@wc8rh7 ~]# sysctl -w net.ipv4.ip_local_reserved_ports="50000" net.ipv4.ip_local_reserved_ports = 50000 [root@wc8rh7 ~]# sysctl -w net.ipv4.ip_local_reserved_ports="" sysctl: malformed setting "net.ipv4.ip_local_reserved_ports="Using procfs directly succeeds: [root@wc8rh7 ~]# echo >/proc/sys/net/ipv4/ip_local_reserved_ports [root@wc8rh7 ~]# sysctl net.ipv4.ip_local_reserved_ports net.ipv4.ip_local_reserved_ports =
sysctl: malformed setting "net.ipv4.ip_local_reserved_ports="
Create a file called e.g. /usr/share/xsessions/safemode.desktop [Desktop Entry] Encoding=UTF-8 Name=Safemode (Xterm) Comment= Exec=xterm Terminal=False TryExec=xterm[Window Manager] SessionManaged=trueRestart SDDM or reboot. Log into "Safemode (Xterm)". Now run: startplasma-x11 or env GNOME_SHELL_SESSION_MODE=pop /usr/bin/gnome-session --systemd --session=pop (all the entries are in /usr/share/xsessions/ - check for Exec ). Check for error messages in the terminal window. To finish this xterm session, simply type exit or reboot. If anything prevents you from using this xterm, type Ctrl + C
I tried disabling IPv6 using /etc/sysctl.conf and after a reboot I cannot get into any of the two DE that I have installed (I am using Pop! OS 20.04). Tried both Pop Desktop and KDE Plasma. The SSDM login screen does show up but after successfully logging in I get a black screen and only the cursor is visible. Ctrl + ALt + F2 does work as intended and if I remove the lines that are supposed to disable IPv6 using Vim and reboot, everything seems to work normally. This is what I added at the end of the file: net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1My question is, how can I even begin to troubleshoot this?
Disabling IPv6 leads to black screen on reboot
Here's a partial answer about what I found out so far. Reading the source code of UFW, I found it just loads in the settings from its own config file when UFW starts. This means that at this point, it will add all settings from that file to the already existing configuration. This will override just the values that are active in this file and will leave all other settings untouched. If this file is made empty, it will do nothing. I also checked each key in that file and found out that there are no overlaps for Ubuntu 18.04. Most settings are new (not included in the existing system files), only one or two will set the same key but also to the same value, so it won't change anything. Based on this, I decided to leave things as they are. Should I ever have to adjust something, I'll have to remember to check three locations:/etc/sysctl.conf /etc/sysctl.d/* /etc/ufw/sysctl.confI still have no answer to the reasons behind this design yet. IMO, UFW should just have added their file in the /etc/sysctl.d directory. It also looks like (in the code) that UFW will never write to this file, so it's just one additional config file that's loaded and that the admin has to maintain. It appears not to be separated because UFW would want to write to it.
There are a lot of network-related settings in /etc/sysctl.conf and a number of files in /etc/sysctl.d/. My data centre operator who has preconfigured the Ubuntu OS to work best in their environment has also added a custom file in there. I guess they come in a good state with the OS and I only need to make changes there if I have good reasons to do so. I don't fully understand all the details about the security issues they may cover so I'd rather not touch them. When I enable the firewall UFW (uncomplicated firewall), its config file says it will override these settings with its own copy in /etc/ufw/sysctl.conf. I have two questions regarding to that:Does this mean that all existing settings in the /etc/sysctl.conf file and /etc/sysctl.d/* files are completely ignored and only /etc/ufw/sysctl.conf is ever regarded? Or will anything mentioned in /etc/ufw/sysctl.conf just override the other existing settings (and nothing will happen if I comment away or delete all of its lines)? Why is a separate file used at all? The old files are still in place but possibly/partially unused or ineffective. That seems like very bad practice and a big source of errors and confusion. It is documented how I could stop this behaviour and switch back to the default file (it's unclear though what then happens to /etc/sysctl.d/*). Why should I not do this? And why is this not the default already?I couldn't find any information about these topics online. There are many places that explain that there are separate files with UFW and I should edit them instead. But noone explains why. I cannot make decisions without knowing the effects.
Why does UFW use a different sysctl.conf file?
My guess is that you're running in a Linux-on-Linux soft virtualization environment such as LXC or OpenVZ where all virtual machines run above the same instance of the Linux kernel. In this kind of environment, kernel parameters (such as the sysctl parameters that you can set via /proc/sys) apply to every virtual machine. Therefore only root in the host environment can modify those parameters, root in a virtual machine cannot. If you need to allow more I/O requests, you'll need to ask your VPS provider.But they'll probably say no, because if 65536 isn't enough for you, you should probably be on a bigger, non-virtualized setup where you aren't sharing I/O.
I would like to edit the file aio-max-nr: root@node:~# echo 65536 > /proc/sys/fs/aio-max-nr -su: /proc/sys/fs/aio-max-nr: Permission deniedKnowing that : root@node:~# ls -lrth /proc/sys/fs/aio-max-nr -rw-r--r-- 1 root root 0 Nov 22 17:02 /proc/sys/fs/aio-max-nrI don't understand why !
Permission denied on aio-max-nr file
Instead of running shell commands, use the sysctl module. If possible, avoid using shell. - ansible.posix.sysctl: name: vm.swappiness value: '10' state: present
When editing configuration files, such as /etc/sysctl.conf for example, it is often useful to do the update in an idempotent way, meaning that if the script is executed multiple times, you don't end up with multiple entries for the configuration change you made. As a real-world instance where I encountered this, I need to edit the above file in multi-stage ansible playbook. But the problem is that if the later stage fails, the playbook will need to be run again, which means that the update command may run multiple times, causing duplication if the update is not idempotent. So the question is how can you update such configuration files in an idempotent way? An example of a non-idempotent update would be: echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.confor in ansible: - name: Set swappiness setting shell: echo "vm.swappiness=10" | sudo tee -a /etc/sysctl.confIdeally if the value of the variable is initially set, it should be replaced with new value.
Edit configuration files idempotently
The value of log_buf_len is set once and for all when the kernel is configured and built OR when it is booted with a parameter log_buf_len=NNN: you cannot change it after that. sysctl generally concerns itself with things that you can change in the running kernel: that's probably the reason why log_buf_len is not included. You can find the configured value of LOG_BUF_SHIFT by just grepping through the kernel config file (assuming that it's available). For example, on my Fedora 29 system, I do $ grep CONFIG_LOG_BUF_SHIFT /boot/config-5.2.11-100.fc29.x86_64 CONFIG_LOG_BUF_SHIFT=18log_buf_len is equal to 2^18 then UNLESS it has been set through the boot command line. If that is the case (or if you don't have access to the config file), then the only way I know is to use gdb to examine the running kernel, but I haven't done that in many years and I really can't remember all the steps - the main difficulty is to get debugging symbols for the kernel you are running. Somebody else will have to provide those instructions though (or perhaps provide a simpler method; e.g. it is possible to write a kernel module that prints out the value when it is loaded - there are many tutorials on writing simple kernel modules, e.g. here: that tutorial dates from the days of the 2.6 kernel and things may be different today but I (naively?) don't expect things to be very different).
I hope to check the value of log_buf_len via sysctl, but sysctl -a doesn't show it, why and is there any other way to check its value
sysctl -a doesn't include log_buf_len
sysctl settings are applied after boot, so in most cases they override equivalent settings given on the kernel command-line (the exceptions are values which can only be set once). Both the kernel oops argument and the kernel.panic_on_oops sysctl map to the same variable, panic_on_oops. This is set by oops_setup if a value is specified on the command-line, and is exported via sysctl in the kernel table. The variable definition shows a third way of setting it: its default value is controlled by a build configuration setting, CONFIG_PANIC_ON_OOPS. As for why the same name isn’t used, there are probably historical reasons, and there remains one significant difference: panic_on_oops expects 0 or 1, whereas oops looks for a value matching “panic”; so while both settings map to the same underlying variable, oops adds a level of indirection.
For example, if I set oops=panic in grub command and I also set kernel.panic_on_oops=0 in sysctl config? ex: in /etc/sysctl.d/ What would happen? Are these two parameters mapping to the same function/feature in the kernel? Why not use the same variable name?
What if kernel parameter conflicted in grub and sysctl?
Without that cache, the HDD can't reorganize writes, which leads to much fragmentation and much more wear. Instead of turning off the cache, you can mount your stick with sync option.
When I used to copy a data over a thumb-drive, even if the writing speed can't exceed 2 MiB/s to the thumb-drive, Linux first copies 600 MB data to it in one second - it just writes to the RAM as cache, then it slowly flushes out the data for like 300 seconds. Caching doesn't actually increase the copy speed in such case. To avoid that behaviour I set vm.dirty_ratio to 0. That makes sure what I write is written in real time, no caching.Problems faced so farWriting to the SSD is now 20 - 30 MiB/s (when copied a 2 GB data from ramdisk to $HOME)! It used to be 300 MiB/s before the change.But that's not a major issue for me, because I can now at least confirm what I copied is written and there's nothing leftover in memory, so that I can work on that file just right after copying without any fear of corrupting the data!Here I Just wanted to know is there any long term side effects of disabling dirty_ratio? I use SSD, HDD, and thumb-drives on my system. The IO schedulers (set using udev rule) are just MQ-Deadline for all non-rotational disks, and BFQ for rotational disks.System Details Kernel: Linux version 5.8.12-xanmod1-1 (makepkg@archlinux) (gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35) #1 SMP PREEMPT Wed, 30 Sep 2020 14:19:49 +0000Edit: Benchmark: I created a new file to the ramdisk: $ >/tmp/x ; xfs_io -c 'pwrite -S 0xa 0 1G' /tmp/x wrote 1073741824/1073741824 bytes at offset 0 1 GiB, 262144 ops; 0.2277 sec (4.392 GiB/sec and 1151213.5997 ops/sec)The file only contains 0xa, which just converts to 10 or "\n" in ASCII. I then mounted, and copied it to my HDD:When dirty_ratio is 20 (default):$ sudo mount /dev/sdb3 /mnt/ ; time sudo cp /tmp/x /mnt/ ; time sudo umount /mnt/ real 0m5.879s user 0m0.013s sys 0m0.392sreal 0m3.566s user 0m0.002s sys 0m0.060sWhen dirty_ratio is 0:$ sudo mount /dev/sdb3 /mnt/ ; time sudo cp /tmp/x /mnt/ ; time sudo umount /mnt/ real 0m29.983s user 0m0.006s sys 0m0.600sreal 0m0.163s user 0m0.000s sys 0m0.052sWhen dirty_ratio is 100 (just for the benchmark):$ sudo mount /dev/sdb3 /mnt/ ; time sudo cp /tmp/x /mnt/ ; time sudo umount /mnt/ real 0m0.408s user 0m0.006s sys 0m0.370sreal 0m9.050s user 0m0.004s sys 0m0.077sThe benchmark denotes it's actually terribly slower to set vm.dirty_ratio to 0...
Is there any long-term side effect of setting vm.dirty_ratio to 0?
The root of this problem was that in my /etc/resolv.conf I had domain hsd1.XX.comcast.net as the first entry which was IPV6, and so I had no DNS. I fixed the problem by simply commenting that line out with a #.
When I disable IPV6 on my Debian install I can't reach the internet, and whenever I ping anything I get ping: unknown host ... This is how I am currently disabling IPV6 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1in my /etc/sysctl.conf
Can't ping anything when IPV6 is disabled
I have updated /etc/security/limits.conf as belowThat's read by pam_limits.so, so it only takes effect for anything that goes through PAM, as in a user login.updated /etc/sysctl.confThat's likely read by some boot scripts, so the changes only take effect after a reboot... (There's systemd-sysctl.service and an old-style /etc/init.d/procps script on my Debian.) The point is, that neither of those files is read instantly, and changes in ulimits never apply to running processes.How can I increase "Max open files" value for this ruby process/app ?Find out whatever starts it, change the ulimit there, and restart the process. If you start it from the command line, changing the limits on the shell and restarting it should do, if you run it from init/systemd/whatever, then you may need to find the correct configuration.
We have a ruby application that started throwing lot of "unable to create new socket: Too many open files" errors recently I have updated "etc/security/limits.conf" as below root soft nofile 6553600 root hard nofile 6553600 nobody soft nofile 655360 nobody soft nofile 655360 mysql hard nofile 655360 mysql hard nofile 655360 * soft nofile 81920 * hard nofile 65000 * - nofile 102400 also updated fs.file-max = 90000 in /etc/sysctl.conf ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 62459 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 10240 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 8192 cpu time (seconds, -t) unlimited max user processes (-u) 62459 virtual memory (kbytes, -v) unlimited file locks (-x) unlimitedulimit -n 10240but still open file limit for ruby process is 1024 cat /proc/13765/limits (pid of ruby app) Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 62459 62459 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 62459 62459 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited usruby process is using more than 1024 files lsof -p 13765 | wc -l1070How can I increase "Max open files" value for this ruby process/app ?
ulimit value not changing for a process
The vm.watermark_scale_factor property in the Linux kernel controls how the kernel manages the available RAM in the system. Increasing the value of this property sets a higher threshold for memory usage before the kernel begins to release inactive memory or file cache in the system. This higher threshold means that the kernel will retain more memory in cache before releasing it. Therefore, if you increase the value of the vm.watermark_scale_factor property, you may notice an increase in RAM consumption in the system, as the kernel will be retaining more memory in cache. This can be especially noticeable in systems with limited available RAM, where the increase in RAM consumption may make the system feel slower or even lead to a memory shortage (in extreme cases). However, it is important to note that the increase in RAM consumption can also lead to an improvement in system performance, as the kernel can access cached data more quickly and, therefore, applications can run more quickly. Overall, the configuration of the vm.watermark_scale_factor property should be carefully adjusted according to the needs and resources of the system to ensure a proper balance between performance and memory availability.
When I configure the vm.watermark_scale_factor property in /etc/sysctl.conf which is the property in charge of indicating to the kernel when the kswapd daemon starts to activate for paging from ram to disk, something happens that I can't find an explanation for: it increases the consumption of ram memory. If I leave its default value which is 10, that is, kswapd is activated when it has 0.1% of memory available, the conky tells me that the computer boots with 1.2gb of ram consumption; but if, for example, I set it to 1000, which is its maximum value, the consumption starts with 2.9 and 3gb without opening anything at all. I have tried this in the Liquorix kernel that I use and also in the Debian one with the same result. Also when I used Linuxmint, I remember that the consumption also increased when the value of that property increased by 200. I set this property to 270, because I notice that when it is set to that value, when the exchange begins the PC does not suffer from slowness. If I leave it by default at 10, the exchange causes a small paralysis of 10 to 15 seconds. To recap, if I leave this property by default at 10 it consumes 1.2gb. If I set it to 270 it consumes 1.7gb and if I set it to 1000 it consumes 2.9-3.0gb without opening any application. I check in the system monitor and there is no process with a high consumption of ram The first thing that comes to mind is that it is a general bug in the kernel. Why does the consumption increase if this property is only to activate the kswapd swap daemon? With vm.watermark_scale_factor=270: $ free -h total used free shared buff/cache available Mem: 5,7Gi 933Mi 3,8Gi 21Mi 1,0Gi 4,1Gi Swap: 4,8Gi 0B 4,8GiWith vm.watermark_scale_factor=1000: $ free -h total used free shared buff/cache available Mem: 5,7Gi 1,1Gi 3,6Gi 39Mi 1,0Gi 2,9Gi Swap: 4,8Gi 0B 4,8GiImage for vm.watermark_scale_factor=1000:the same shows the system monitor. All that consumption without opening anything.
Why does setting the vm.watermark_scale_factor property increase ram consumption?
The answer is: Per user. See the demonstration below: ┌[rovanion][RiggenBuntu]:~ └$ keyctl add user a-key some-data @u 812046028┌[root][RiggenBuntu]:/ └# cat /proc/key-users 0: 95 94/94 83/1000000 1687/25000000 1000: 5 5/5 5/200 61/20000 ┌[root][RiggenBuntu]:/ └# sysctl -w kernel.keys.maxbytes=62 kernel.keys.maxbytes = 62 ┌[root][RiggenBuntu]:/ └# cat /proc/key-users 0: 95 94/94 83/1000000 1687/25000000 1000: 5 5/5 5/200 61/62┌[rovanion][RiggenBuntu]:~ └$ keyctl add user b-key more-data @u add_key: Disk quota exceeded
The Linux kernel's documentation on its Key Retention Service states that:/proc/sys/kernel/keys/maxkeys /proc/sys/kernel/keys/maxbytes These files hold the maximum number of keys that each non-root user may have and the maximum total number of bytes of data that each of those users may have stored in their keys.Though, I find, the wording isn't clear on whether it is per user or per key ´maxbytes´ can be used to store key data. So is it per user or per key?
Is kernel.keys.maxkeys per user or per key?
If that is the only place in the file where those lines appear: sed '/#Size Of RAM (In GB): 23/,/kernel.msgmnb/d' /etc/sysctl.confThat searches for everything in between and including the first and last lines of that block and deletes it. I included the first line in its entirety instead of a smaller string in case Size or something else in it appears elsewhere in the file. I have also used kernel.msgmnb as you've stated that the number is different on other machines. That command will send the changes to stdout so that you can make sure that the changes are what you want. If they are, you can do an inplace edit of the file by adding the -i switch: sed -i '/#Size Of RAM (In GB): 23/,/kernel.msgmnb/d' /etc/sysctl.conf
on some of my machines i have this block of setting in sysctl.conf(the numbers are different on each machine) : #Size Of RAM (In GB): 23 kernel.shmmni= 2547 kernel.shmmax= 365482458 kernel.shmall= 25471984 #kernel.sem=<SEMMSL> <SEMMNS> <SEMOPM> <SEMMNI> kernel.sem= 325 12496852 74 3654 kernel.msgmni= 1204 kernel.msgmax= 57452 kernel.msgmnb= 74235the location of this block is different sometimes. i wanted to write a bash that remove this old settings and insert new configuration. since it is sysctl.conf i need to do it safely. how i can remove them with sed or grep and be sure that only this block will remove?
remove specific sysctl.conf setting
An excerpt from man sysctl.conf:Comments are denoted by a "#" at the beginning of a line.
Is it right to comment line with # in the file sysctl.conf? I ask because I am not sure if the comment lines would be read or not. more /etc/sysctl.conf#net.core.rmem_default = 1048576 #net.core.rmem_max = 4194304 #net.core.wmem_default = 1048576 #net.core.wmem_max = 4194304net.ipv4.tcp_timestamps=0 net.ipv4.tcp_sack=1 net.core.netdev_max_backlog=250000 net.core.rmem_max=4194304 net.core.wmem_max=4194304 net.core.rmem_default=4194304 net.core.wmem_default=4194304 net.core.optmem_max=4194304 net.ipv4.tcp_rmem=4096 87380 4194304 net.ipv4.tcp_wmem=4096 65536 4194304
linux + sysctl.conf configuration