I usually remote login to the server at my school. I have a user name and password. The command is 'ssh -l username -p port machineName'. (username is mine, port is a number and machineName is the machines in the school) I assigned this command to an alias called log but then when i log in it always asks me for a password. Is there any way I can make my alias enter the password after the command too?


SSH doesn't let you pass a password, as it would be considered insecure (you should use Public Keys instead, but the school would probably have to set it up on their end too).

PuTTY allows a password to be passed from the command-line: -pw: specify a password
Note that the -pw option only works when you are using the SSH protocol.

and there's also SSHPass:

Sshpass is a tool for non-interactivly performing password authentication with SSH's so called "interactive keyboard password authentication".


If it is enabled for your ssh installation, you should follow a procedure to create what are known as public encrypted keys, and then use those keys to auto-log you in. It is rather quite an easy procedure, and you should be able to bypass the whole password entry issue.

Search the net with the search phrase, "generate rsa keys pairs ssh" to find a plethora of pages which describe the process. Here is just one such link.

I typically do not use a pass phrase. I'll let other commentators provide any justification to do the opposite.

[8] ls -ld ~/.ssh
drwx------+ 2 whmcclos staff 68 Feb  4 09:05 /Users/whmcclos/.ssh
[9] ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/whmcclos/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/whmcclos/.ssh/id_rsa.
Your public key has been saved in /Users/whmcclos/.ssh/id_rsa.pub.
The key fingerprint is:
77:93:ef:57:40:7d:ef:9b:6e:99:4a:a3:8a:8b:81:a9 whmcclos@Williams-MacBook-Pro.local
The key's randomart image is:
+--[ RSA 2048]----+
|               . |
|              . o|
|             .  o|
|             .. .|
|        S . +  o |
|    o    . . o  o|
|   o .       o. *|
|  .   o .   o..*.|
| E   . o.... .=o |
[10] ls -l .ssh
total 8
-rw-------+ 1 whmcclos staff 1679 Feb  4 09:06 id_rsa
-rw-r--r--+ 1 whmcclos staff  417 Feb  4 09:06 id_rsa.pub

[11] cat $HOME/.ssh/id_rsa.pub | ssh myRemoteHost 'cat >> .ssh/authorized_keys && echo "Key copied"'

type in your password for the last time. Now, you should be able to ssh into the remote host sans the password.

Please note that the $HOME/.ssh folder is assumed to have been created on the two hosts, the one you are coming from and the one you are logging into. If they haven't, create those folders first, before doing the above. Also note that the permissions on the $HOME/.ssh folder should be set to chmod 700 $HOME/.ssh on both hosts.

On step [9], just accept the default entry for each question, but it would be worth-while to learn what the questions mean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.