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?
- What’s a .sh file?
- How to fix ‘sudo: no tty present and no askpass program specified’ error?
- How do I grep recursively?
- What does pss mean in /proc/pid/smaps
- apt-get error: Sub-process /usr/bin/dpkg returned an error code (1)
- How do I grep recursively?
- how to find libstdc++.so.6: that contain GLIBCXX_3.4.19 for RHEL 6?
- How to extract C source code from .so file?
- subprocess.Popen(): OSError: [Errno 8] Exec format error in python?
- How to substitute shell variables in complex text files
- How can I recursively find all files in current and subfolders based on wildcard matching?
- “sed” command in bash
- How to exclude a directory in find . command
- How can I find all *.js file in directory recursively in Linux?
- Argument list too long error for rm, cp, mv commands
- Difference between using “chmod a+x” and “chmod 755”
- WSL – GEDIT Unable to init server: Could not connect: Connection refused
- Python subprocess.Popen “OSError: [Errno 12] Cannot allocate memory”
- Install tkinter for Python
- How to open some ports on Ubuntu?
- Given two directory trees, how can I find out which files differ by content?
- What does it mean to mount a file system in linux?
- curl: (6) Could not resolve host: google.com; Name or service not known
- -bash: fork: Cannot allocate memory
- CentOS error – sudo: effective uid is not 0, is sudo installed setuid root?
- Merge / convert multiple PDF files into one PDF
- scp from Linux to Windows
- Bash script: bad interpreter
- PHP and mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
- How to grep and replace
- node.js: cannot find module ‘request’
- What does “&” at the end of a linux command mean?
- How to recursively download a folder via FTP on Linux
- httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
- How do I write stderr to a file while using “tee” with a pipe?
- How to include file in a bash shell script
- Does Mac OS X use Linux?
- bash sh – command not found
- Hosting multiple WordPress sites on single server – best practices?
- security+best practices: root or www-data on a wordpress content folder?
- SELinux security vs WordPress updates
- Folder Permissions + Security Concerns
- How can I run Debian stable but install some packages from testing?
- Environment variables of a running process on Unix?
- Meaning of the buffers/cache line in the output of free
- How to cd into a directory with this name “-2” (starting with the hyphen)?
- Is it possible to detach a process from its terminal? (Or, “I should have used screen!”) [duplicate]
- How can I port forward with iptables?
- Is it possible to make Nginx listen to different ports?
- Linux command line best practices and tips?
- How to run command as user who has /usr/sbin/nologin as Shell?
- How to get pid of just started process
- How to disable everything in crontab -l?
- df says disk is full, but it is not
- What is the maximum port number?
- How to sort ps output by process start time?
- Is there a proper way to clear logs?
- How do I join two named pipes into single input stream in linux
- How should an IT department choose a standard Linux distribution?