Using ssh-add to Simplify Logins2:28 with Jay McGavren
First, we'll try logging in as our new deployment user. Then we'll show you how to use the `ssh-add` command so you don't have to type your private key passphrase all the time.
Okay, our deploy user is set up. 0:00 Let's try logging in, and see what we can do. 0:02 First, on our development account on the server, 0:05 we're going to need to restart the SSH service, just to make sure that there 0:07 are no changes to config that didn't get picked up. 0:11 So we're gonna type sudo service ssh restart, 0:13 and that'll restart the SSH service. 0:18 Then we'll exit out of our shell to return to our local computer. 0:25 Now let's SSH into the server using our deploy account, 0:28 ssh deploy@ and the address of our host. 0:33 It'll ask us to enter the passphrase that we set up when creating the private key, 0:40 so let's enter that now. 0:44 And it'll use that private key to log into the system. 0:49 Now entering that passphrase every time we wanna log in can be a bit of a pain. 0:53 So let me show you a program we can use to save us a little trouble. 0:57 So let's exit out of our server back to our local computer. 1:00 And we're going to use the ssh-add command. 1:05 What ssh-add does is it'll ask you to enter the passphrase for your private key. 1:09 And it'll remember that passphrase in your system's RAM, so that you don't have to 1:20 enter it again until such time as you restart your local computer. 1:24 So now I can try to SSH as the deploy user to hostcom again. 1:29 And this time, ssh-add will remember my passphrase from my private key, and 1:36 I logon instantly and automatically. 1:41 I can exit again and connect again, and I don't have to type in my passphrase. 1:44 While we're logged in, let's confirm that our setup for 1:50 the sudo command is working correctly as well. 1:52 So let's try something that we would normally need administrative access for. 1:55 So let's try and look at the contents of the /etc/sudoers file, 1:59 and we'll notice that permission is denied. 2:04 But if we bring the same command up again, and try to put sudo at the front of it, 2:08 we'll be asked for the password that we set up when creating the deploy account, 2:13 And there's the contents of the file. 2:22 It looks like our sudoer setup is working. 2:25
You need to sign up for Treehouse in order to download course files.Sign up