# Ensure sudo Commands Use pty

- Source: https://support.icompaas.com/support/solutions/articles/62000235535-ensure-sudo-commands-use-pty
- Section: [Solutions](https://support.icompaas.com/support/solutions) › [CIS Amazon Linux 2 Benchmark v3.0.0](https://support.icompaas.com/support/solutions/62000112696) › [CIS Amazon Linux 2 Benchmarks](https://support.icompaas.com/support/solutions/folders/62000169265)
- Last updated: 2026-05-29
- Publisher: iCompaas, Inc. (https://www.icompaas.com)

Profile Applicability: • Level 1

Description:  
 Configuring sudo to use a pseudo-terminal (pty) ensures that all commands executed via sudo are run in a controlled terminal environment. This improves logging fidelity and prevents certain security issues related to input/output redirection.

Rationale:  
 Requiring pty usage for sudo commands enhances audit trails and mitigates risks associated with non-interactive command execution or session hijacking.

Impact:  
 Pros:

-   Improves logging and auditing of sudo command executions.  
      
    
-   Enhances security by controlling command execution environment.  
      
    

Cons:

-   May cause compatibility issues with some automated scripts or applications.  
      
    

Default Value:  
 Depending on the sudo version and configuration, pty may or may not be required by default.

Pre-requisites:

-   Root or sudo privileges to modify sudoers configuration.  
      
    

Remediation:

### Test Plan:

Using Linux command line:

Check sudoers configuration for requiretty or equivalent:

sudo grep requiretty /etc/sudoers /etc/sudoers.d/\*

1.  Verify that requiretty is set or that pty is enforced.
    

### Implementation Plan:

Using Linux command line:

Edit the sudoers file safely using visudo:  
  
visudo

Add or ensure the following line is present to require pty:  
  
Defaults requiretty

1.  Save and exit visudo.  
      
    

### Backout Plan:

Using Linux command line:

1.  Remove or comment out the Defaults requiretty line if necessary.
    
2.  Save changes using visudo and test sudo functionality.  
      
    

References:

-   [NIST SP 800-53 Revision 5 - AU-12  
      
    ](https://csrc.nist.gov/publications/detail/sp/800-53/rev-5/final#au-12)

## Related compliance guidance

- [SOC 2 compliance: a practical implementation guide for cloud-native SaaS teams](https://support.icompaas.com/compliance/soc-2-trust-services-criteria): Configuration checks like this one are the technical half of a SOC 2 / ISO 27001 programme — the guide shows where they fit, what else an auditor expects, and how to evidence them.
- [ISO/IEC 27001:2022 compliance: a practical implementation guide](https://support.icompaas.com/compliance/iso-27001-2022): ISO 27001 Annex A.8 (technological controls) is where cloud hardening evidence lands; the guide shows how to run the ISMS around it.
