preface

One day, the boss suddenly told me that the company had a project that needed to be launched as soon as possible. You should ask the students in Infra to assign you a machine, and try to set up the project as soon as possible. Besides, you should configure accounts for other students, so that they could use the machine when they needed.

I thought, “Oops, big guy, I can’t…

SSH Login Configuration

No, but the momentum can not be weak. Ask the big guys of infra for the machine first. Submit id_rsa.pub and 10 minutes later, drop!

Infra 🧍♂️ : Configure SSH config, then use [email protected] to log in to me: ok, thanks big guy!Copy the code
# ~/.ssh/config

ForwardAgent yes

Host *
    AddKeysToAgent yes
    UseKeychain yes
    IdentityFile ~/.ssh/id_rsa

Host ssh-proxy.xxx.cn
    ProxyCommand none
    Port 2201

Host dev.xxx.cn
    ProxyCommand ssh -q [email protected] nc %h %p
Copy the code

I took a closer look at the SSH config configuration, and it wasn’t hard. Because man ssh_config will take you to the ssh_config door.

ProxyCommand When SSH is connected to the machine, the following command is executed, that is, SSH to our springboard machine.

The nc command will link the corresponding host and post, namely dev.xxx.cn

Then, we just need SSH [email protected] to happily log in to the machine.

Adding a User for Linux

Yeah, just press it. (Serious face)

#Create dev group
groupadd dev

#Add a user named just, specify the home directory, and specify the user group dev
useradd -g dev -d /home/just just

#Set the password for user just
passswd just

#Set just to the owner of the /home/just directory
chown just /home/just

#Log in as user just
su just

#Create the.ssh directory and set the mod to 700 (only the owner has read, write, execute permissions).
mkdir -m 700 /home/just/.ssh

#Write SSH pub key for just little brotherecho "...... ssh pub key......" > /home/just/.ssh/authorized_keys
#Set permissions for authorized_keys
chmod 600 /home/just/.ssh/authorized_keys

#Run road (ctrl-c)
sh root

#Change the AllowUsers setting of SSH Config
vi /etc/ssh/sshd_config

AllowUsers root just

:wq

#Check the SSHD configuration
/usr/bin/sshd -T

#Restart SSHD the configuration takes effect
service sshd restart
Copy the code