0
0

More than 3 years have passed since last update.

AmazonLinuxに作業用ユーザを追加するTeraTermマクロ

Last updated at Posted at 2020-06-15

Amazon LinuxをLaunchして最初にやりたい作業用ユーザの追加をTeraTermマクロでやる

TeraTermマクロを用意する

"USERID" のところに、作りたいユーザ名を入れて、拡張子 ".ttl" で保存

USERID = 'hirohiro-kun'

sendln 'sudo su'

wait 'root'
sendln 'adduser 'USERID

wait 'root'
sendln 'usermod -G wheel 'USERID

wait 'root'
var3a = 'echo "'
var3b = ' ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers'
sendln var3a USERID var3b

wait 'root'
sendln 'su - 'USERID

wait USERID
sendln 'mkdir .ssh && chmod 700 .ssh && touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys'

wait USERID
sendln 'ssh-keygen -t rsa'
wait 'Enter file in which to save the key'
sendln
wait 'Enter passphrase'
sendln
wait 'Enter same passphrase again'
sendln

wait USERID
sendln 'cat .ssh/id_rsa.pub >> .ssh/authorized_keys'

wait USERID
sendln 'exit'

wait 'root'
var1a = 'cp /home/'
var1b = '/.ssh/id_rsa /home/ec2-user/'
var1c = '.pem && exit'
sendln var1a USERID var1b USERID var1c

wait 'ec2-user'
var2a = 'sudo chmod 644 '
var2b = '.pem && ls'
sendln var2a USERID var2b

end

ec2-userでAmazon Linuxにログインする

いつもどおりの方法でログイン

マクロを実行する

TeraTermメニューの[コントロール → マクロ] をクリックして、作っておいた .ttl ファイルを開く

秘密鍵をダウンロード

ec2-user の home directory に USERID.pem ファイルが出来るので、ダウンロード

秘密鍵を使ってログイン

ec2-user ではなく USERID と USERID.pem を使って、いつもどおりの方法でログイン

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0