I use a passphrase protected ssh keyfile to connect to a server. Each time I open a new terminal I have to re-enter the passphrase. Can I make Ubuntu remember the passphrase until I log-off or for an hour or so?
I use a passphrase protected ssh keyfile to connect to a server. Each time I open a new terminal I have to re-enter the passphrase. Can I make Ubuntu remember the passphrase until I log-off or for an hour or so?
We can use
sshpass
in combination with ssh in order to login to a server.You can install
sshpass
viasudo apt-get install sshpass
if your haven't already.The trick is the usage of both sshpass and ssh in a single line like this:
But that's something you already knew. And in order to avoid writing your password everytime you wish to log in to your server you can create a custom script which will execute that command for you when you write its name, something like:
Change the proper data, save the code in a file and name it whatever you wish, easy to remember and easy to type. Please note that I am using
-p 2222
because that's the port number I use instead of22
, your server may usea different port number
so check for that information if something seems not to be working as expected.I am going to name it
ssh1
and give it the proper execution permissions with:Then move the script to your
/usr/bin
folder withsudo mv ssh1 /usr/bin
, provide your user password and that's it.After this you can enter any terminal, write your script's name (
ssh1
in this case) and hit ENTER and the script will do the trick for you.A screenshot of my custom script in action is here:
NOTE: You must manually log in to your ssh server at least once in your life in order to the script be able to automatically do its magic.
Good luck!