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

推荐订阅源

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 Getting started with GNU screen - Beginners Guide Basics of Power over Ethernet (PoE) Difference between RSS and Atom 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
SSH Troubleshooting Guide - Ittavern.com
2023-01-17 · via Ittavern.com

I won't go into specific cases in this blog post. This is a general guide on how to gather the necessary information that will help you to get your problem fixed.

In this post, I'll use a Linux client and server as a reference.

Logging #

Client

Get the verbose logging with the -v flag. This normally is enough, but if you need even more information, use -vv and -vvv.

Server

You can find the logs for your SSH Server here /var/log/auth.log or /var/log/secure.

For troubleshooting sessions, it is recommended to increase the log level from the default LogLevel INFO to LogLevel DEBUG1 in your SSH server configuration sshd_config. This will gives you all the necessary information. The following log levels are available: QUIET, FATAL, ERROR, INFO, VERBOSE, DEBUG, DEBUG1, DEBUG2, and DEBUG3. Remember to restart the SSH server after changing this setting.

Another method is to check journalctl if you use systemd. The logs should be available via sudo journalctl -r -u ssh -u sshd.

Often enough, restarting the server is not an option. You simply can add anoher process with the same options, but inceased debug level and another port. This allows you to monitor the logs for a specific client without interupting the main SSH server.

sudo /usr/sbin/sshd -dDp 2222

Side note: make sure to use the absolute path or you will be greeted by the following error message sshd re-exec requires execution with an absolute path.

Thanks to youRFate on Lobste.rs for the tip!

Common errors #

As mentioned, there are many more, but the following list will give you a great starting point.

Hostname resolution #

error output
ssh: Could not resolve hostname example.com: Name or service not known

This error message implies a problem with the DNS.

  • check that the hostname is correct
  • use the IP instead to test general connectivity
  • check hostname resolution with nslookup or other tools

Connection timeout #

Error output
ssh: connect to host 10.10.10.10 port 22: connection timed out

This error tells you that you can't reach the server at all.

Wrong destination IP:
verify that the destination IP is correct
Routing:
can the client reach the destination? Check the routing table and use ICMP to double-check (ping and traceroute). Consider that ICMP sometimes is blocked by network firewalls!
Firewalls:
check the firewalls on the client, server, and network firewalls and make sure that the connection is allowed.

Connection refused #

Error output
ssh: connect to host 10.10.10.10 port 22: connection refused

You can reach the server, but the server refuses the connection

Wrong destination IP:
verify that the destination IP is correct
Listening SSH server port:
is the default SSH port 22 used? You can check it with the Port 22 in the /etc/ssh/sshd_conf file on the server.
is the server listening on the communicated port? Check on the server with ss -tulpen | grep -i :22 (use netstat on older Linux versions) or use tools like nmap to find the listening port (disclaimer: do not scan server you do not have the permission for)
SSH server running:
make sure that the SSH server is running, e.x. with systemctl status sshd

Permission denied #

Permission denied (publickey,password)

Most likely a problem with the authentication.

Wrong user credentials:
make sure that you use the correct username and password or private key.
as a side note: the login as root is often forbidden by common security measures.
Missing permissions on the server:
make sure that the user is allowed to log in via SSH.
/etc/ssh/sshd_config > AllowUsers or AllowGroups
Wrong authentication method:
most commonly, you'd log in via password or public key authentication.
use the -v on the client to look for the following entry: debug1: Authentications that can continue: password,publickey. This gives you information on what the server accepts.
to force an authentication option on the client, you could use the -o flag with SSH options. To force the login via password you could use something like this: ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no user@10.10.10.10.
if the desired option is unavailable, it must be configured on the server. /etc/ssh/sshd_config: PubkeyAuthentication yes and PasswordAuthentication yes. It is recommended to use public key authentication only.
Wrong permission and/or ownership of SSH-related files:
most SSH servers check how permissive e.x. the SSH keys are, and can deny access if they are too permissive.
sudo chmod 700 ~/.ssh
sudo chmod 644 ~/.ssh/authorized_keys
sudo chmod 644 ~/.ssh/known_hosts
sudo chmod 644 ~/.ssh/config
sudo chmod 600 ~/.ssh/nameofthekey        # private key
sudo chmod 644 ~/.ssh/nameofthekey.pub    # public key
Public key is missing in the ~/.ssh/authorized_keys file:
the public key must be added to the a.m. file. A how-to can be found in this post.
Private key no longer accepted on the server:
some private keys are no longer considered secure, so the server could refuse the login with those keys.
the best solution would be to update the SSH applications and generate new keys.
a workaround would be to add the insecure key algorithm to the SSH server config to the accepted keys PubkeyAcceptedKeyTypes.

SSH protocol version #

Protocol major versions differ: 1 vs. 2

The client and server do not work with the same protocol version. That said that you should only use SSHv2 and disable SSHv1.

Client

With the -v flag you can see what the server offers:
debug1: Remote protocol version 2.0 [...]

With the flags -1 and -2 you can decide whether the client should use SSH protocol version 1 or 2, respectivly.

Server

On the server, you can check the provided SSH protocol version in the configuration file:
grep Protocol /etc/ssh/sshd_config
Protocol 1 # SSHv1
Protocol 2 # SSHv2
Protocol 1,2 # SSHv1 + SSHv2

If this option is missing, the mordern SSH server will use SSHv2 by default. It is worth adding it just to be sure and have it documented.

Failed host key verification #

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.

Clearing the host key from ~/.ssh/known_hosts our use ssh-keygen -R <ip-of-destination. You should be able to connect normally.

If you were not informed about any changes, please contact the SSH server administrator to verify that everything is still secure.

Unable to negotiate ciphers, MACs, or KexAlgorithms #

Unable to negotiate with 10.10.10.10: no matching key exchange method found.
Their offer: diffie-hellman-group1-sha1

Use the -vv flag on the client to output the necessary information. On the server, you can see the information with the LogLevel DEBUG2 and check with the following commands what is accepted by the server.

Ciphers:
ssh -Q cipher
MACs:
ssh -Q mac
KexAlgorithms:
ssh -Q kex

Most commonly old SSH software is the reason for those errors. They still support old and insecure methods, which are no longer supported by modern applications.

There are workarounds with the -o flag to set temporary options, but I am not too familiar with it.

ssh -o KexAlgorithms=+diffie-hellman-group1-sha1 user@10.10.10.10

Connect without startup file #

This is not that common but there are ways to lock you out after changes to the startup files like .bashrc, .profile, and so on. You simply can avoid loading those profile files with the following command.

ssh -t user@host bash --norc --noprofile

Handling SSH sessions with escape sequences #

SSH provides some escape sequences with which you can kill the session on the client.

Supported escape sequences:
 ~.   - terminate connection (and any multiplexed sessions)
 ~B   - send a BREAK to the remote system
 ~C   - open a command line
 ~R   - request rekey
 ~V/v - decrease/increase verbosity (LogLevel)
 ~^Z  - suspend ssh
 ~#   - list forwarded connections
 ~&   - background ssh (when waiting for connections to terminate)
 ~?   - this message
 ~~   - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

Side note: Start with a RETURN and keep SHIFT pressed while typing ~ and e.x. ? to get this message. This depends on your keyboard layout.

You can send the sequence through one or more SSH tunnel by adding ~ in front of the sequence.