惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

Ittavern.com

Wimage - Hosting Open-Source Image Uploader with Podman and external S3 Storage Switching from Hugo to picopaper Encryption using SSH Keys with age in Linux ETag in nginx - Simple Resource Caching Sending nginx Logs to Loki with Grafana Alloy How to: Cisco ISE backup to SFTP repository with public key authentication Dummy IP & MAC Addresses for Documentation & Sanitization Deploying ISSO Commenting System for Static Content using Docker Generate a Vanity v3 Hidden Service Onion Address with mkp224o ssh-audit Primer - Audit your SSH Server mtr - More Detailed Traceroute - Network Troubleshooting My Personal Backup Strategy - August 2024 iperf3 - User Authentication with Password and RSA Public Keypair Adding a trash can to Linux with trash-cli Bandwidth Measurement using netcat on Linux Getting started with rsync - Comprehensive Guide Cron Jobs on Linux - Comprehensive Guide with Examples SSH Server Hardening Guide v2 Port Knocking with knockd and Linux - Server Hardening Getting started with rclone - Data transmission Getting started with dig - DNS troubleshooting Getting started with Fail2Ban on Linux Getting started with netcat on Linux with examples URL explained - The Fundamentals Troubleshooting Asking The Right Questions Create tmux layouts using bash scripts Getting started with tcpdump - Ittavern.com Curl on Linux - Reference Guide Getting started with nmap scripts My Offsite Backup - March 2023 Getting started with iperf3 - Network Troubleshooting ICMP echo requests on Linux and Windows - Reference Guide Simulate an unreliable network connection with tc and netem on Linux Detecting Rogue DHCP Server - Ittavern.com Basics of the Linux Bash Command History with Examples Basics of Power over Ethernet (PoE) Difference between RSS and Atom SSH Troubleshooting Guide - Ittavern.com Backup Guide - how to secure crucial data SSH - run script or command at login Linux - unmount a busy target safely Visual guide to SSH tunneling and port forwarding Guide to Wireshark display filters Online Security Guide - Ittavern.com My IT EDC tool kit v2212 10 prompts - 1000 AI generated images - openAI Dall-E SSH - How to use public key authentication on Linux Ways to support open-source projects Getting started with nmap - Ittavern.com nginx - simple and native authentication function Linux - How to work with complex commands EICAR test file - riskless method to test your antivirus and firewall solution Linux - connect to a serial port with screen Podman / Docker - expose port only to the localhost of the host machine Tmux - reload .tmux.conf configuration file My use cases for CyberChef Nginx - simple permanent or temporary redirects Getting started with tmux - Ittavern.com Tmux - synchronize the input of all panes within a window Nginx - check your public IP CyberChef - How to remove empty lines
Getting started with GNU screen - Beginners Guide
2023-01-28 · via Ittavern.com

Screen is a terminal multiplexer and has a wide feature set. It allows you to split your terminal window into multiple windows (split screen feature), detach sessions to let commands run in the background, connect to a device via serial interface, and many more. Screen sessions keep running even if you disconnect, which is especially great for unreliable connections. There are more advanced use cases, but we will focus on the basics.

Basics

You can have multiple sessions within the screen and each session can contain multiple windows. When you use the split screen function, each panel would be a window called region in screen.

 screen
    │
    │
    ├───── session 29324.x
    │         │
    │         ├────── window 0: name x
    │         │
    │         └────── window 1: name y
    │
    └───── session 29399.a
               │
               ├───── window 0: name a
               │
               └───── window 1: name b

Escape combination (Prefix) #

In this blog post, I'll call the escape combination 'prefix', but there are multiple names for it: meta key, leading key, escape combination, and some others.

The prefix tells the terminal that the following command or shortcut will be used in the screen context. Almost every shortcut starts with it and the default prefix is CTRL + a. So, if you see Prefix in the reference section, I mean this key combination. I'll show you how to change the prefix as an example in the configuration section.

A list of all default key bindings can be found in the official documentaion.

Configuration files #

Screen won't create the startup configuration file by default but will look for these two files if it gets started.

~/.screenrc / /usr/local/etc/screenrc

Comments in the configuration file start with a #.

The following two sections will show some simple examples of different configurations.

Example 1: change prefix for screen #

Adding the following line to you your configuration file changes the prefix to CTRL + f:
escape ^Ff

You can change it to a difference key combination, especially as the default prefix key combination is commonly used otherwise.

#Do not show copyright msg at the start of a session
startup_message off

Simply add these lines to your configuration file, and the copyright message won't appear again.

Logging #

Before we start with the sessions and windows, it might be beneficial to talk about logging. For most troubleshooting sessions, it is required to save the logs. I am going to show you some ways to do it.

Hardcopy #

Use Prefix + h to create an output file with the content of the current screen window you are in. It will be saved as hardcopy.n ('n' for the number of the current window ) in the directory from where you have started the screen initially. If you repeat the shortcut, the initial file will be overwritten.

If you want to append the output to a file, you can add hardcopy_append on to your configuration file.

If you want to change the directory in which the harcopy files will be saved, simply add hardcopydir /your/dir/ to your configuration file.

Continuous logging #

Logging is disabled by default.

You can start a logged screen session with -L flag + -Logfile /path/to/logfile.txt. If you are already in a session, you can activate it with Prefix + SHIFT + h. The output file will be called screenlog.n, where 'n' is the number of the current window.

Working with sessions #

Show all sessions:
screen -ls
kuser@pleasejustwork:~$ screen -ls
There are screens on:
        29265.demo-session      (27.01.2023 02:19:51)   (Detached)
        26508.pts-8.pleasejustwork      (26.01.2023 23:20:50)   (Detached)
2 Sockets in /run/screen/S-kuser.
Start a new session:
screen
Start a new session with a specific name:
screen -S nameofthissession
Start a new detached session and run a command:
screen -d -m ping 10.10.10.10
Detach the current session:
Prefix + d
Create new session if there is none, or re-attach the last session:
screen -d -RR
Re-attach session in terminal:
screen -r 2232 # screen will auto complete if the prompt is unique
screen -r nameofthissession # either use the session number or the name
Kill session in terminal:
screen -X -S nameofsession quit
screen -X 269 quit # auto-completes if unique
Rename session in terminal:
screen -S OLDSESSIONNAME -X sessionname NEWSESSIONNAME
Prefix + :sessionname NEW-NAME # screen command to change the current session name

Working with Windows #

Show list of all windows of current session:
Prefix + SHIFT + w
Rename the current windows:
Prefix + SHIFT + a
Jump to the next window:
Prefix + SPACE
Jump to the previous window:
Prefix + p
Kill the current window:
exit
Prefix + k

Working with Regions / Split screen #

Screen has the feature to show multiple windows in a split screen. Every window would then be a so called 'Region' in screen.

Horizontally split window into two regions:
Prefix + SHIFT +s
Vertically split window into two regions:
Prefix + |
Jump to the next region:
Prefix + Tab
Close the current region:
Prefix + x
the window won't be terminated and just the split screen will be removed.
Close all but the current region:
Prefix + q
Fit the regions to a resized terminal window:
Prefix + SHIFT +f

Layouts #

You could create layouts, and save and reuse them later. This topic is out of the scope of this post and I am going to write about it later. You can get a reference and further information in the official documentaion.

Screen commands #

It can be used to try out configurations and screen-specific commands.

Prefix + : + config Prefix + :logfile ~/path/to/new/logfile.txt

I am not too familiar with screen commands, so I won't go into detail. A list of all commands can be found in the official documentaion.

Check if you are still in a screen session

Screen sets an environment variable STY. If the output is empty, you are not in a screen session.

kuser@pleasejustwork:~$ echo $STY
22829.demo

This won't work if you start up screen and SSH into a remote machine. Without further configuration, the variables stay local.


Another environment variable you could try is TERM.

kuser@pleasejustwork:~$ screen
kuser@pleasejustwork:~$ echo $TERM
screen.xterm-256color
kuser@pleasejustwork:~$ exit
kuser@pleasejustwork:~$ echo $TERM
xterm-256color

Screen will add the prefix screen. in front of it.

This works even after connecting to a remote machine but presumes that you didn't mess with the TERM variable.


Another method would be to work with the screen prefix. You could simply use Prefix + CTRL + t to let screen tell you the time in the bottom left corner.

screen-time