OpenBSD Handbook

    Theme
    • Part I. Install & Configure
      • Introduction to OpenBSD
      • Installing OpenBSD
      • The X Window System
      • Networking on OpenBSD
      • System Configuration
      • OpenBSD Basics
      • Managing Software: Packages and Ports
    • Part II. Daily Operations
      • OpenBSD Desktop Environments
      • Multimedia
      • Printing
      • Linux Compatibility
      • Windows Compatibility
      • Games
    • Part III. System Administration
      • Virtualization
      • Storage and File Systems
      • Updating and Upgrading
      • Localization
      • The OpenBSD Boot Process
      • Security
    • Part IV. Networking & Daemons
      • Services
        • Database
          • MariaDB
          • PostgreSQL
          • Redis
          • memcached
        • Directory
          • YP (NIS)
          • LDAP
        • File
          • NFS
          • Samba
        • FTP Services
          • ftpd
          • ProFTPD
          • vsftpd
          • Pure-FTPd
          • TFTP
        • Mail
          • OpenSMTPD Mail Server
          • Dovecot IMAP and POP3 Server
          • Postfix
          • Exim
          • Rspamd
        • Name
          • Unbound DNS Resolver
          • NSD Authoritative DNS Server
          • BIND DNS Server
        • Networking
          • OpenBGPD
          • rad
          • DHCP on OpenBSD
          • slaacd
        • Web
          • Apache HTTP Server
          • nginx Web Server
          • OpenBSD httpd Web Server
          • relayd Reverse Proxy
        • Logging
          • syslogd
        • Monitoring
          • SNMP
        • Remote Access
          • Audit OpenSSH
          • OpenSSH Server
        • File Synchronization
          • rsync
        • Messaging
          • RabbitMQ Message Broker
        • Time
          • NTP Time Synchronization
        • Load Balancing
          • Build Redundant Load-Balanced Gateways
          • Load Balance Services with NAT or DSR
          • Build an HA HTTPS Load Balancer
      • PF
        • pfctl cheat sheet
        • PF Anchors
        • PF Filter Rules
        • PF Forwarding
        • PF Lists and Macros
        • PF Load Balancing
        • PF Logging
        • PF NAT
        • PF Options
        • PF Policies
        • PF Shortcuts
        • PF Tables
      • Advanced Networking
        • High Availability and State Replication
        • Multi-WAN and Policy-Based Routing
        • VPN and Cryptographic Tunneling
        • Classic and Lightweight Tunnels
        • IPv6 at Scale
        • QoS and Traffic Shaping
        • MPLS and Label Distribution
        • Network Services at Scale
        • Virtualization and Host Networking
        • Large-Scale L2 and L3 Design
        • Telemetry, Logging, and Flow Export
        • Hardening and Operational Safety
        • Reference Architectures
        • Troubleshooting Playbooks
      • Serial Communication
    • Part V. Miscellaneous
      • Virtualization Cheat Sheet
      • OpenBSD Cheatsheet
      • How-to Guides
        • Installation and First Boot
          • Complete the First 30 Minutes After Installation
          • Check Hardware Compatibility Before Installing
          • Bootstrap Wi-Fi Firmware Without Ethernet
          • Run OpenBSD as a Virtual Machine Guest
          • Install OpenBSD on a VPS or Cloud Server
          • Install OpenBSD with Full-Disk Encryption
          • Dual-Boot OpenBSD on a UEFI System
          • Automate OpenBSD Installation with Autoinstall and PXE
        • Desktops and Laptops
          • Set Up OpenBSD as a Laptop or Workstation
          • Configure Laptop Power Management
          • Troubleshoot Web Browsers on OpenBSD
          • Use Plan 9 Tools on OpenBSD
          • Build a Minimal Desktop with suckless Tools
          • Install Z shell (zsh)
        • Networking and Remote Access
          • Create an Administrator Account with doas and SSH Keys
          • Configure Secure Remote Access with OpenSSH
          • Use FIDO Security Keys with OpenSSH
          • Configure Wi-Fi Roaming and Wired Failover
          • Troubleshoot PF, NAT, and Routing
          • Route Multiple VLANs with PF
          • Configure a Road-Warrior WireGuard VPN
          • Route IPv6 Networks without NAT
          • Test OpenBGPD with Two Providers
          • Unlock an Internal Service with an SSH Key
          • Build a Simple Router and Firewall
        • Servers and Services
          • Set Up WordPress on OpenBSD
          • Build a Mail Server with OpenSMTPD, Dovecot, and Rspamd
        • Security, Maintenance and Recovery
          • Establish a Conservative Security Baseline
          • Recover Access and Reset the Root Password
          • Collect OpenBSD Diagnostic Evidence
          • Troubleshoot Package Installation and Update Failures
          • Schedule Recurring Maintenance
          • Monitor an OpenBSD System
          • Back Up and Restore an OpenBSD System
          • Configure softraid RAID1
          • Recover an OpenBSD System That Does Not Boot
        • Building, Automation and Virtual Machines
          • Manage OpenBSD with Ansible
          • Build Third-Party Software from Ports
          • Build OpenBSD from Source
          • Plan a Docker Workload Migration to OpenBSD
      • OpenBSD for Linux Users
      • OpenBSD for FreeBSD Users
      • OpenBSD for macOS Users
    • OpenBSD FAQ
    • OpenBSD Architectures
      • OpenBSD Package Search
        • Synopsis
        • Install the Package
        • Change the Login Shell
        • Create a Minimal Configuration
        • Return to the Base Shell

        Install Z shell (zsh)

        Synopsis #

        Z shell, normally called zsh, is an interactive shell and scripting language available through OpenBSD packages. This guide installs the package, verifies its registered login-shell path, changes one user’s login shell, and creates a minimal configuration without depending on a third-party configuration framework.

        OpenBSD’s base system includes ksh(1) . Installing zsh is optional and does not replace the shell used by system scripts.

        Install the Package #

        Install zsh with pkg_add(1) :

        doas pkg_add zsh
        

        Confirm the installed executable and its entry in shells(5) :

        command -v zsh
          # Display the executable selected by the current PATH
        grep '^/usr/local/bin/zsh$' /etc/shells
          # Confirm that the package registered zsh as a permitted login shell
        

        The package normally installs the executable as /usr/local/bin/zsh and registers it in /etc/shells. Investigate the package installation if either check fails. Do not add an unverified path to /etc/shells.

        Change the Login Shell #

        Use chsh(1) as the target user:

        chsh -s /usr/local/bin/zsh
        

        The new login shell starts at the next login. Confirm the account database entry with getent(1) :

        getent passwd "$USER"
        

        Keep an existing login session open while testing the new shell. A syntax error in a user startup file can then be repaired from the working session.

        Create a Minimal Configuration #

        When no startup files exist, the first interactive zsh session may offer the zsh-newuser-install configuration helper. It can create a basic ~/.zshrc. A short, hand-written configuration also works:

        touch ~/.zshrc
          # Create the file without replacing existing content
        chmod 600 ~/.zshrc
          # Restrict the user configuration to its owner
        

        Add settings one at a time and test each change. The following example enables completion and saves a modest command history:

        autoload -Uz compinit
        compinit
        
        HISTFILE=$HOME/.zsh_history
        HISTSIZE=1000
        SAVEHIST=1000
        setopt append_history
        

        Start a clean interactive shell to test the configuration:

        zsh
        

        If startup fails, bypass user startup files with:

        zsh -f
        

        Third-party frameworks can execute code during every shell startup and may replace substantial parts of ~/.zshrc. They are outside the base installation procedure and should be reviewed, pinned, and maintained separately if used.

        Return to the Base Shell #

        To restore OpenBSD’s base Korn shell as the login shell:

        chsh -s /bin/ksh
        

        Log out and log in again, then remove the zsh package only after confirming that no account still uses it as a login shell.

        Report a bug
        • Synopsis
        • Install the Package
        • Change the Login Shell
        • Create a Minimal Configuration
        • Return to the Base Shell