I would prefer the ssh-keygen -y -e -f <private key>
way instead of the accepted answer of How do you test a public/private DSA keypair? on Stack Overflow.
ssh-keygen -y -e -f <private key>
takes a private key and prints the corresponding public key which can be directly compared to your available public keys. (Hint: beware of comments or key-options.)
(How the hell is it doing that? I can only hope the public key is encoded directly or indirectly in the private key…)
I needed this myself and used the following Bash one-liner. It should output nothing if the keys belong together. Apply a little -q
to the diff in scripts and diff only sets the return code appropriately.
PRIVKEY=id_rsa
TESTKEY=id_rsa.pub
diff <( ssh-keygen -y -e -f "$PRIVKEY" ) <( ssh-keygen -y -e -f "$TESTKEY" )
Related Posts:
- Is it normal to get hundreds of break-in attempts per day?
- “POSSIBLE BREAK-IN ATTEMPT!” in /var/log/secure — what does this mean?
- mysql_config not found when installing mysqldb python interface
- Meaning of exit status 1 returned by linux command
- ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
- Pseudo-terminal will not be allocated because stdin is not a terminal
- X11 forwarding request failed on channel 0
- mysql_config not found when installing mysqldb python interface
- Pseudo-terminal will not be allocated because stdin is not a terminal
- How to download a file from server using SSH?
- Explanation of polkitd Unregistered Authentication Agent
- connect to host localhost port 22: Connection refused
- Getting stty: standard input: Inappropriate ioctl for device when using scp through an ssh tunnel
- EC2 ssh Permission denied (publickey,gssapi-keyex,gssapi-with-mic)
- How to configure WP filesystem access in Linux (Ubuntu Server)?
- WordPress sites being filled with random PHP files
- What permissions should my website files/folders have on a Linux webserver?
- Can I automatically add a new host to known_hosts?
- Can I nohup/screen an already-started process?
- Permission denied (publickey). SSH from local Ubuntu to Amazon EC2 server
- How to reconnect to a disconnected ssh session
- how to disable SSH login with password for some users?
- Keeping a linux process running after I logout
- How to handle security updates within Docker containers?
- how do you create an ssh key for another user?
- REJECT vs DROP when using iptables
- SSH keypair generation: RSA or DSA?
- Does getting disconnected from an SSH session kill your programs?
- Tips for Securing a LAMP Server
- Can you have more than one ~/.ssh/config file?
- How to add a security group to a running EC2 Instance?
- SSH from A through B to C, using private key on B [closed]
- Show all users and their groups/vice versa
- SSHFS mount that survives disconnect
- Heartbleed: how to reliably and portably check the OpenSSL version?
- Temporarily ignore my `~/.ssh/known_hosts` file?
- How can I fully log all bash scripts actions?
- What’s wrong with always being root?
- Hundreds of failed ssh logins
- protocol version mismatch — is your shell clean?
- What is the difference between /sbin/nologin and /bin/false?
- How do I deal with a filename that starts with the hyphen (-) character?
- Chmod 777 to a folder and all contents [duplicate]
- Bash: No such file or directory?
- Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?
- Confused about stdin, stdout and stderr?
- What’s a .sh file?
- Amazon Linux: apt-get: command not found
- How to set the environmental variable LD_LIBRARY_PATH in linux
- ssh connect Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)
- What’s a .sh file?
- How can I symlink a file in Linux? [closed]
- How to fix ‘sudo: no tty present and no askpass program specified’ error?
- Kill detached screen session [closed]
- How do I grep recursively?
- How do I grep recursively?
- Why do you need to put #!/bin/bash at the beginning of a script file?
- How to get the url of the current svn repo?
- What does pss mean in /proc/pid/smaps
- apt-get error: Sub-process /usr/bin/dpkg returned an error code (1)
- How do I find all files containing specific text on Linux?
- How to unmount a busy device
- “Couldn’t find a file descriptor referring to the console” on Ubuntu bash on Windows
- How to unmount a busy device
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- performing HTTP requests with cURL (using PROXY)
- Where can I find php.ini?
- gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- No space left on device
- How do I grep recursively?
- How can I recursively find all files in current and subfolders based on wildcard matching?
- How to perform grep operation on all files in a directory?
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- Amazon Linux: apt-get: command not found
- How to install grub after installing Windows 10
- Linux: ‘Username’ is not in the sudoers file. This incident will be reported
- how to find libstdc++.so.6: that contain GLIBCXX_3.4.19 for RHEL 6?
- How to extract C source code from .so file?
- Pass a password to ssh in pure bash
- subprocess.Popen(): OSError: [Errno 8] Exec format error in python?
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- How to substitute shell variables in complex text files
- -bash: syntax error near unexpected token `newline’ for display command
- How can I recursively find all files in current and subfolders based on wildcard matching?
- How do I use grep to search the current directory for all files having the a string “hello” yet display only .h and .cc files?
- SSH using python script
- Curl command for https ( SSL )
- How can I exclude directories from grep -R?
- How to exclude a directory in find . command
- “sed” command in bash
- How can I exclude directories from grep -R?
- Changing the resolution of a VNC session in linux
- Using putty to scp from windows to Linux
- gcc: error: unrecognized command line option
- How to exclude a directory in find . command
- How can I find all *.js file in directory recursively in Linux?
- Linux error while loading shared libraries: cannot open shared object file: No such file or directory
- How to set proxy for wget?
- Shell command to tar directory excluding certain files/folders