cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh ; cat >> .ssh/authorized_keys"

Enter your ssh password one last time

Enter your ssh public key in the remote end for future key-based authentication. Just type your password one last time. The next time you should be able to login with the public key. If you don't have a key, generate one with ssh-keygen. Requires Bourne-compatible shell in the remote end.

5
By: jsiren
2009-02-18 22:13:04

These Might Interest You

  • By default sudo 'remembers' password for a few minutes, so that you do not need to re-enter password for a series of sudo commands that might follow within a short time duration. However, sometime you might want sudo to instantly 'forget' the password. (Next sudo command will need you to reenter the password) Credit: I first learned this while listening to one of the 'tuxradar' podcast. Show Sample Output


    17
    sudo -K
    b_t · 2010-10-05 12:44:26 0
  • Just run the command, type your password, and that's the last time you need to enter your password for that server. This assumes that the server supports publickey authentication. Also, the permissions on your home dir are 755, and the permissions on your .ssh dir are 700 (local and remote).


    14
    cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
    bendavis78 · 2009-02-11 17:40:12 2
  • Be aware of using the --password argument as it will appear your password in plain text on the screen. You may use -p argument instead, it will prompt you to enter you password in hidden mode.


    -1
    cat schema.sql data.sql test_data.sql | mysql -u user --password=pass dbname
    tristan_ph · 2009-03-24 08:39:40 1
  • NOTE: When doing these commands when asked for questions there might be flowing text from the pv doing the progress bar just continue typing as if its not there, close your eyes if it helps, there might be a yes or no question, type "yes" and ENTER to it, and also it will ask for a password, just put in your password and ENTER I talk alot more about this and alot of other variations of this command on my site: http://www.kossboss.com/linuxtarpvncssh Show Sample Output


    0
    cd /srcfolder; tar -czf - . | pv -s `du -sb . | awk '{print $1}'` | ssh -c arcfour,blowfish-cbc -p 50005 root@destination.com "tar -xzvf - -C /dstfolder"
    bhbmaster · 2013-05-30 07:21:06 0
  • You can ask repeatedly for a non-blank password using this function: function read_password() { while [ ! -n "$USER_PASSWORD" ]; do read -s -p"Password: " USER_PASSWORD if [ ! -n "$USER_PASSWORD" ]; then echo "ERROR: You must specify a valid password, please try again" fi echo done } Also you can set a time out (in seconds) to write the password read -t 10 -s -p"Password: " USER_PASSWORD_VARIABLE if [ ! $? -eq 0 ]; then echo "Time out!" fi


    14
    read -s -p"Password: " USER_PASSWORD_VARIABLE; echo
    h3nr1x · 2011-07-20 20:22:42 0
  • You should really use keys. Really. I'm serious. But if you have to add your key, change password etc. for a long list of servers, this might help.


    -1
    (sleep 3; echo "MyAwesomePassword"; sleep 3) |socat - EXEC:'ssh username@server "hostname"',pty,setsid,ctty
    TommyBotten · 2011-08-24 14:13:18 0

What Others Think

ssh-copy-id is another option; it's not part of OpenSSH, but is often available on different Unixes.
SaintAardvark · 482 weeks and 5 days ago
I'd recommend something more akin to: cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh && cat >> .ssh/authorized_keys" Note the "&&" in place of the original ";"; this way, if the "mkdir" fails (say, if "/home" is out of space), the final "cat" won't be attempted.
christianhenry · 479 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: