With regard to the structure of RSA key files, and how the public key is related to the private key - you can see that the modulus in the public key file is the product of the two large primes contained in the private key file by doing the following:
Generate a private key:
openssl genrsa -out private.key 2048
Extract the public key from the private key file:
openssl rsa -in private.key -pubout > public.key
Now, use the following command to view the two large primes in the private key file:
openssl rsa -noout -text -inform PEM -in private.key
In my case, the two large primes are the following (of course, yours will be different):
prime1=00:e7:c4:87:45:a8:9a:1c:62:17:b4:18:a8:28:af:a0:64:f7:ed:58:73:c4:fa:9b:e7:08:68:90:d6:c7:65:f5:33:15:ca:24:d4:aa:94:8b:15:96:4d:5e:12:dd:f2:c7:8a:27:d8:fb:81:b8:c5:fd:b0:51:71:37:92:d8:51:5f:43:2d:c5:15:ba:3a:0a:fd:ef:3b:a0:26:50:3a:79:4f:92:e6:5f:12:a4:a2:9e:ea:bf:e7:32:c0:ec:fd:50:71:d0:56:73:6f:3b:4f:fe:79:21:6e:81:3d:06:03:41:0e:97:1b:2a:7e:e3:a6:e8:3b:53:2f:2c:27:98:8d:a5:6e:6f
prime2=00:c9:26:67:48:c7:b8:8c:9f:51:37:77:f6:ad:6d:96:68:82:e6:3b:ad:fe:e2:2d:0c:78:c7:29:6c:22:5a:f9:be:83:f3:5f:8e:e3:95:b1:d0:71:53:80:14:98:50:d8:cb:5d:1a:be:d4:dc:35:86:66:9a:82:26:38:f5:1a:4d:dc:56:f9:78:ec:67:bb:8d:24:e4:a3:18:ac:d6:0b:76:aa:df:b0:5f:a8:75:83:57:00:d6:43:be:a7:23:36:80:89:ea:cd:4b:b5:e6:cb:db:3f:85:08:c9:b8:63:78:16:f4:46:ad:16:45:87:8a:aa:84:84:c4:dc:19:ff:1c:5f:af
Use the following command to view the modulus in the public key file:
openssl rsa -noout -text -inform PEM -in public.key -pubin
In my case, I get:
modulus=00:b6:1c:12:e3:bc:3b:f3:4e:be:a1:dd:26:40:b4:35:d5:12:79:d2:63:3a:c4:f0:6f:b2:5c:13:fe:67:32:58:5b:2a:5a:b2:83:dc:db:e1:86:1d:ac:38:12:73:66:fd:f9:fe:24:cc:61:6b:c0:c8:76:b8:3e:dd:ed:9f:f1:c9:fb:f5:19:a9:32:67:0c:9a:46:36:1e:40:ed:9c:b3:22:b9:66:f4:8e:dc:56:10:d1:39:43:ec:35:dd:eb:fd:4c:a0:72:cf:cd:01:17:d9:69:6c:d9:29:c9:ce:bf:57:cc:23:b3:9a:26:c4:25:d3:80:0b:e1:28:c4:f0:38:8e:37:4a:c8:e8:9d:0c:be:75:3e:00:56:04:17:4a:eb:15:1c:7b:78:f6:01:66:78:92:1b:12:58:62:2d:c7:25:2b:db:63:07:5b:be:0e:2c:18:7d:9c:ba:2c:78:9c:1d:66:63:eb:8d:bd:36:8c:21:6f:ae:41:89:91:dd:f3:d0:96:d1:75:00:39:bf:a4:05:12:fb:b2:75:81:07:cd:e6:e0:80:d7:5e:45:9f:ee:0a:11:a7:c6:4c:e1:5a:7c:5b:15:d1:c2:f4:c6:36:5d:81:e6:cc:35:10:0c:fa:79:34:35:fd:74:fb:0c:95:fe:1c:7f:ef:19:b4:b3:21:c8:dd:35:ae:e1
You can write a short python program to multiply the two large primes to calculate the modulus, and output all three values in hex format.
prime1=0x00e7c48745a89a1c6217b418a828afa064f7ed5873c4fa9be7086890d6c765f53315ca24d4aa948b15964d5e12ddf2c78a27d8fb81b8c5fdb051713792d8515f432dc515ba3a0afdef3ba026503a794f92e65f12a4a29eeabfe732c0ecfd5071d056736f3b4ffe79216e813d0603410e971b2a7ee3a6e83b532f2c27988da56e6f
prime2=0x00c9266748c7b88c9f513777f6ad6d966882e63badfee22d0c78c7296c225af9be83f35f8ee395b1d0715380149850d8cb5d1abed4dc3586669a822638f51a4ddc56f978ec67bb8d24e4a318acd60b76aadfb05fa875835700d643bea723368089eacd4bb5e6cbdb3f8508c9b8637816f446ad1645878aaa8484c4dc19ff1c5faf
modulus=prime1*prime2
print('prime1', hex(prime1))
print('prime2', hex(prime2))
print('modulus', hex(modulus))
This produces
prime1: 0xe7c48745a89a1c6217b418a828afa064f7ed5873c4fa9be7086890d6c765f53315ca24d4aa948b15964d5e12ddf2c78a27d8fb81b8c5fdb051713792d8515f432dc515ba3a0afdef3ba026503a794f92e65f12a4a29eeabfe732c0ecfd5071d056736f3b4ffe79216e813d0603410e971b2a7ee3a6e83b532f2c27988da56e6f
prime2: 0xc9266748c7b88c9f513777f6ad6d966882e63badfee22d0c78c7296c225af9be83f35f8ee395b1d0715380149850d8cb5d1abed4dc3586669a822638f51a4ddc56f978ec67bb8d24e4a318acd60b76aadfb05fa875835700d643bea723368089eacd4bb5e6cbdb3f8508c9b8637816f446ad1645878aaa8484c4dc19ff1c5faf
modulus: 0xb61c12e3bc3bf34ebea1dd2640b435d51279d2633ac4f06fb25c13fe6732585b2a5ab283dcdbe1861dac38127366fdf9fe24cc616bc0c876b83edded9ff1c9fbf519a932670c9a46361e40ed9cb322b966f48edc5610d13943ec35ddebfd4ca072cfcd0117d9696cd929c9cebf57cc23b39a26c425d3800be128c4f0388e374ac8e89d0cbe753e005604174aeb151c7b78f6016678921b1258622dc7252bdb63075bbe0e2c187d9cba2c789c1d6663eb8dbd368c216fae418991ddf3d096d1750039bfa40512fbb2758107cde6e080d75e459fee0a11a7c64ce15a7c5b15d1c2f4c6365d81e6cc35100cfa793435fd74fb0c95fe1c7fef19b4b321c8dd35aee1
As you can see, this shows that the modulus calculated by multiplying the two large primes from the private key file matches the modulus contained in the public key file.
With regard to the question about whether or not the modulus is actually embedded in the private key file - it is. You can run the following command to convert the base64-encoded binary in the private key file to hex:
cat private.key | grep -v ^- | base64 -d | xxd -c32
This produces:
00000000: 3082 04a4 0201 0002 8201 0100 b61c 12e3 bc3b f34e bea1 dd26 40b4 35d5 1279 d263 0................;.N...&@.5..y.c
00000020: 3ac4 f06f b25c 13fe 6732 585b 2a5a b283 dcdb e186 1dac 3812 7366 fdf9 fe24 cc61 :..o.\..g2X[*Z........8.sf...$.a
00000040: 6bc0 c876 b83e dded 9ff1 c9fb f519 a932 670c 9a46 361e 40ed 9cb3 22b9 66f4 8edc k..v.>.........2g..F6.@...".f...
00000060: 5610 d139 43ec 35dd ebfd 4ca0 72cf cd01 17d9 696c d929 c9ce bf57 cc23 b39a 26c4 V..9C.5...L.r.....il.)...W.#..&.
00000080: 25d3 800b e128 c4f0 388e 374a c8e8 9d0c be75 3e00 5604 174a eb15 1c7b 78f6 0166 %....(..8.7J.....u>.V..J...{x..f
000000a0: 7892 1b12 5862 2dc7 252b db63 075b be0e 2c18 7d9c ba2c 789c 1d66 63eb 8dbd 368c x...Xb-.%+.c.[..,.}..,x..fc...6.
000000c0: 216f ae41 8991 ddf3 d096 d175 0039 bfa4 0512 fbb2 7581 07cd e6e0 80d7 5e45 9fee !o.A.......u.9......u.......^E..
000000e0: 0a11 a7c6 4ce1 5a7c 5b15 d1c2 f4c6 365d 81e6 cc35 100c fa79 3435 fd74 fb0c 95fe ....L.Z|[.....6]...5...y45.t....
00000100: 1c7f ef19 b4b3 21c8 dd35 aee1 0203 0100 0102 8201 003e fa26 6e2b 4270 39e3 2306 ......!..5...........>.&n+Bp9.#.
00000120: df9b b0b6 8d20 fe90 0b50 df9a 6686 3fe1 8a31 15f0 0856 f556 96d3 6216 f3d2 7f24 ..... ...P..f.?..1...V.V..b....$
00000140: 44fd 33b8 d123 5a86 738a 57f8 fb55 6c28 436c f4a8 ed41 2dc6 9d6f 95a4 2473 c2b2 D.3..#Z.s.W..Ul(Cl...A-..o..$s..
00000160: a179 7759 a2d4 3fee c7b3 dbcc ff08 c63f 3aa7 c9c9 1e13 9659 46ef 8078 3cf4 3cc7 .ywY..?........?:......YF..x<.<.
00000180: 5580 4654 8a64 2a03 0e02 26ca 3951 7c4f dee3 300b 5e73 b57f 0a9e eac6 ac02 4261 U.FT.d*...&.9Q|O..0.^s........Ba
000001a0: 1051 9009 15ca b50d 249d 79b7 1483 4727 3bab 70a6 a3f3 4cac 949c 5930 77fd f6d9 .Q......$.y...G';.p...L...Y0w...
000001c0: 4b4e 216f 920b 27e2 9482 260a 0f02 c335 7ea0 d9e2 8ecd 4d24 fbfb c30b 8f35 db4f KN!o..'...&....5~.....M$.....5.O
000001e0: ff28 a240 3dad adce c9c1 e110 5f0b e1e0 223f 5df9 54b4 008d 563e 0372 4d20 2f09 .(.@=......._..."?].T...V>.rM /.
00000200: 2aa8 b56b d594 ee07 839b 6f56 ac44 a6dc d0ca b1c8 2102 8181 00e7 c487 45a8 9a1c *..k......oV.D......!.......E...
00000220: 6217 b418 a828 afa0 64f7 ed58 73c4 fa9b e708 6890 d6c7 65f5 3315 ca24 d4aa 948b b....(..d..Xs.....h...e.3..$....
00000240: 1596 4d5e 12dd f2c7 8a27 d8fb 81b8 c5fd b051 7137 92d8 515f 432d c515 ba3a 0afd ..M^.....'.......Qq7..Q_C-...:..
00000260: ef3b a026 503a 794f 92e6 5f12 a4a2 9eea bfe7 32c0 ecfd 5071 d056 736f 3b4f fe79 .;.&P:yO.._.......2...Pq.Vso;O.y
00000280: 216e 813d 0603 410e 971b 2a7e e3a6 e83b 532f 2c27 988d a56e 6f02 8181 00c9 2667 !n.=..A...*~...;S/,'...no.....&g
000002a0: 48c7 b88c 9f51 3777 f6ad 6d96 6882 e63b adfe e22d 0c78 c729 6c22 5af9 be83 f35f H....Q7w..m.h..;...-.x.)l"Z...._
000002c0: 8ee3 95b1 d071 5380 1498 50d8 cb5d 1abe d4dc 3586 669a 8226 38f5 1a4d dc56 f978 .....qS...P..]....5.f..&8..M.V.x
000002e0: ec67 bb8d 24e4 a318 acd6 0b76 aadf b05f a875 8357 00d6 43be a723 3680 89ea cd4b .g..$......v..._.u.W..C..#6....K
00000300: b5e6 cbdb 3f85 08c9 b863 7816 f446 ad16 4587 8aaa 8484 c4dc 19ff 1c5f af02 8181 ....?....cx..F..E.........._....
00000320: 00e1 38c3 d357 625b 4e9f 862d a7cb d1cf 660e dfa0 62ef fa30 e233 f399 3c7e 0c80 ..8..Wb[N..-....f...b..0.3..<~..
00000340: 58a2 460b c075 fb5f a51c a816 50f3 49e7 ca43 aac1 cd6f 8747 5dbd e6ed 804f a1d3 X.F..u._....P.I..C...o.G]....O..
00000360: 96ee b564 c5d1 7db9 026f c8d3 3287 8037 69a3 60a4 3744 a875 ab02 baf9 6bd3 4607 ...d..}..o..2..7i.`.7D.u....k.F.
00000380: 33d3 aedd 5aa0 03c4 264e c25c 50a9 7ce0 f6ca 3963 914a 32c6 e3b1 2591 5cd7 d8f9 3...Z...&N.\P.|...9c.J2...%.\...
000003a0: 1502 8180 256b 9f8b 4a9c 6a8c b8ef 38c2 0b41 77d9 b980 5b59 e330 f070 8187 8b8d ....%k..J.j...8..Aw...[Y.0.p....
000003c0: 3256 fa5f 16ed 0fb9 e55c d3d7 933d 9576 3f5f caf5 0a3d 0f83 49f4 2b2c ab51 cb0a 2V._.....\...=.v?_...=..I.+,.Q..
000003e0: 8d8e 772d a680 829e 782d cbf4 3114 a662 80ef 6104 28d9 06f2 afe9 df25 a8b6 b1a1 ..w-....x-..1..b..a.(......%....
00000400: 264b dd5d caf0 a645 10ca 9bdf 1540 ad46 403a f70a 3a9b b8a8 f6ae 354a b1e8 6d89 &K.][email protected]@:..:.....5J..m.
00000420: e88b bec1 0281 8100 e531 018b fb6a aa77 2b6a 04d8 ae8c 3487 de6e 0aff cc9a 4843 .........1...j.w+j....4..n....HC
00000440: df3f 9ea8 76f8 bdf2 6917 2c9e 93eb baa1 0a1e 1050 73b1 ea13 c37f 8e31 1ea6 8cca .?..v...i.,........Ps......1....
00000460: 297f 7f12 7528 5832 de3c 0618 f3ef 815b 10a8 4cf5 4cef e7c9 808c 30e6 dfe0 0462 )...u(X2.<.....[..L.L.....0....b
00000480: 4cbd ba75 a03c 0c5d 5145 e4f9 dc78 bb24 843b 562c 7ad7 cb30 e957 57f9 bbfa 8e56 L..u.<.]QE...x.$.;V,z..0.WW....V
000004a0: 0724 ff43 fe10 2059 .$.C.. Y
As you can see, the modulus is embedded in the private key file, starting at the 13th byte. You can also see that the first prime starts at the 282nd byte, and the second prime starts at the 350th byte