I am trying to nested SSH using Paramiko where I will connect to Server X from my local machine and from there I will connect to Server Y. Here to connect to Server X I am u
You cannot use port forwarding to implement the jump, if you need to use a private key stored on the jump server.
Either download the key to the local machine. If you do not want to physically store the key on the local machine, you can download it to memory in your Python code only. See Loading key from an SSH jumphost using Paramiko.
Otherwise you would have to implement the jump by running ssh
client on the jump server, which will pick up the private key stored there (what is normally a lame solution):
ssh.exec_command("ssh root@Y pwd")